var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var BaseUI = (function (_super) {
    __extends(BaseUI, _super);
    function BaseUI(skinname) {
        var _this = _super.call(this) || this;
        _this.skinName = skinname;
        return _this;
    }
    BaseUI.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        this.checkFit();
        this.initData();
        this.initView();
        this.initEvent();
        if (this.logic != null) {
            this.logic.init();
        }
        this.inited = true;
    };
    /**适配处理 */
    BaseUI.prototype.checkFit = function () {
        //这个高是游戏数据里舞台高
        this.height = GameData.stageHeight;
        //如果背景这张图不为空
        if (this.img_bg != null) {
            //背景图的高等于舞台的高
            this.img_bg.height = GameData.stageHeight;
        }
        //如果重置的背景不为空
        if (this.rect_bg != null) {
            //重置背景的高等于舞台的高
            this.rect_bg.height = GameData.stageHeight;
        }
    };
    /**初始化数据 */
    BaseUI.prototype.initData = function () {
    };
    /**初始化界面 */
    BaseUI.prototype.initView = function () {
    };
    /**初始化事件 */
    BaseUI.prototype.initEvent = function () {
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
    };
    BaseUI.prototype.clearEvent = function () {
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
    };
    BaseUI.prototype.clear = function () {
        this.clearEvent();
        if (this.logic != null) {
            this.logic.clear();
        }
        this.logic = null;
    };
    BaseUI.prototype.close = function () {
        if (this.parent != null) {
            this.parent.removeChild(this);
        }
    };
    return BaseUI;
}(eui.Component));
__reflect(BaseUI.prototype, "BaseUI");
var Player = (function (_super) {
    __extends(Player, _super);
    function Player(vo) {
        var _this = _super.call(this) || this;
        _this.p1 = new egret.Point();
        _this.p2 = new egret.Point();
        _this.frame = 0;
        _this.ui = 0;
        //初始化位置随机，只执行一次
        _this.an = true;
        /**判断现在玩家的状态 */
        _this.ss = true;
        /**承接刀碰撞后返回的数量 */
        _this.back_knifes_num = 5;
        Player.instance = _this;
        _this.touchEnabled = false;
        _this.touchChildren = false;
        _this.vo = vo;
        _this.init();
        return _this;
        //创建一个计时器对象
    }
    Player.getInstance = function () {
        return this.instance;
    };
    Player.prototype.init = function () {
        this.initData();
        if (this.vo != null) {
            this.initView();
        }
    };
    Player.prototype.initData = function () {
        //初始化让刀等于0
        this.knifes = [];
        this.knife_index = 0;
    };
    Player.prototype.updateVO = function (vo) {
        this.vo = vo;
        if (this.bg == null) {
            this.initView();
        }
        else {
            this.bg.texture = RES.getRes("yuan_" + this.vo.bg_id);
            this.updateView();
            this.updateKnifes();
        }
    };
    Player.prototype.initView = function () {
        //实例化一个新的con
        this.con = new egret.DisplayObjectContainer();
        //添加场景
        this.addChild(this.con);
        if (this.bg == null) {
            this.state = PLAYERSTATE.CRUISE;
        }
        this.bg = ObjectPool.getObject("BaseBitmap");
        this.bg.texture = RES.getRes("yuan_" + this.vo.bg_id);
        this.addChild(this.bg);
        this.lbl_name = ObjectPool.getObject("BaseTextField");
        this.lbl_name.fontFamily = "SimHei";
        this.lbl_name.textAlign = "center";
        this.lbl_name.text = this.vo.name;
        this.lbl_name.anchorOffsetX = this.lbl_name.width / 2;
        this.lbl_name.anchorOffsetY = this.lbl_name.height / 2;
        this.addChild(this.lbl_name);
        this.updateView();
        this.updateKnifes();
    };
    Object.defineProperty(Player.prototype, "state", {
        get: function () {
            return this._state;
        },
        set: function (v) {
            if (this._state == v) {
                return;
            }
            this.setState(v);
        },
        enumerable: true,
        configurable: true
    });
    Player.prototype.setState = function (v) {
        this._state = v;
        switch (v) {
            case PLAYERSTATE.CRUISE:
                this.wait();
                break;
            case PLAYERSTATE.MOVE:
                this.move();
                break;
            case PLAYERSTATE.DEFENCE:
                this.defence();
                break;
            case PLAYERSTATE.DEAD:
                break;
            case PLAYERSTATE.ATK:
                break;
        }
    };
    Player.prototype.wait = function () {
        if (this.an == true) {
            this.x = Math.random() * DesignConst.mapwidth;
            this.y = Math.random() * DesignConst.mapheight;
            this.an = false;
        }
    };
    Player.prototype.move = function () {
    };
    Player.prototype.defence = function () {
        this.vo.direction = null; //可视效果：首尾相连时，刀间距变大
        this.updateKnifes();
    };
    /**边界判断 */
    Player.prototype.checkBound = function () {
        return false;
    };
    /**转向
     * @param a 当b为null时 角度直接改变成a，否则a-b随机一个范围
     * @param b 当b为null时 角度直接改变成a，否则a-b随机一个范围
     */
    /** AI转向 */
    Player.prototype.changeDirection = function (a, b) {
        if (a === void 0) { a = 0; }
        if (b === void 0) { b = 360; }
        if (b == null) {
            this.vo.direction = a;
        }
        else {
            this.vo.direction = GameUtil.between(a, b, 0);
        }
    };
    /**玩家每帧更新坐标 */
    Player.prototype.updateCrood = function () {
        var hu = this.vo.direction * Math.PI / 180;
        this.x += this.vo.move_speed * Math.sin(hu);
        this.y -= this.vo.move_speed * Math.cos(hu);
    };
    /**1秒后更新发射状态 */
    Player.prototype.timerComFunc = function () {
        this.state = PLAYERSTATE.CRUISE;
        //实例化一个新的con
        this.con = new egret.DisplayObjectContainer();
        //添加场景
        this.addChild(this.con);
        this.knife_index = 0;
        this.updateKnifes();
        this.ss = true;
    };
    /**0.3秒后调动子弹发射脚本 */
    Player.prototype.time = function () {
        this.atkk(this.jiao);
    };
    /** 每一帧执行 */
    Player.prototype.update = function () {
        var _this = this;
        /**控制玩家和敌人刀的每一帧选择 */
        if (this.state == PLAYERSTATE.ATK) {
            //如果是玩家移动则发射飞刀
            if (this.ss == true) {
                if (this.vo.direction != null) {
                    this.jiao = this.vo.direction;
                }
                else {
                    this.jiao = 0;
                }
            }
            if (this.ss == true && this.vo.name == "玩家") {
                this.con.rotation = 0;
                this.ss = false;
                if (this.knifes.length > 0) {
                    egret.setTimeout(function () { _this.time(); }, this, 300);
                }
                egret.setTimeout(function () { _this.timerComFunc(); }, this, 1000);
            }
        }
        /**攻击时改变状态 */
        if (this.ss == false) {
            this.state = PLAYERSTATE.ATK;
        }
        if (this.state != PLAYERSTATE.ATK && this.state != PLAYERSTATE.DEFENCE) {
            this.con.rotation += this.vo.turn_speed;
        }
        if (this.vo.direction != null && this.vo.move_speed != null) {
            this.updateCrood();
        }
        this.checkEatKnife();
        this.frame++;
        if (this.state == PLAYERSTATE.DEFENCE && this.frame % 40 == 0) {
            this.addCircle();
        }
        if (this.frame % 4 == 0) {
            //刀的数量++
            this.knife_index++;
            //如果刀的数量大于等于刀数组的总长
            if (this.knife_index >= this.knifes.length) {
                //刀的数量归零
                this.knife_index = 0;
            }
            //传刀的数量进方法
            this.updateKnifeInArr(this.knife_index);
        }
        /**每帧调用生成刀的方法 */
        if (this.n > this.b) {
            this.updateKnifes();
        }
    };
    /**通过tween动画把刀发射出去 */
    Player.prototype.atkk = function (rotation) {
        var _this = this;
        var hu = rotation * Math.PI / 180;
        var a = 400 * Math.sin(hu);
        var b = 400 * Math.cos(hu);
        var x = this.con.x + a;
        var y = this.con.y - b;
        //let p = this.CheckBoun(x, y, 3);
        var p = this.CheckBound(x, y); //控制tween动画运行时移动方向及距离
        var t = this.knifes.length - 1; //声明t是为了在攻击时首先获取刀数组的长度，防止在其他状态时刀的损失
        this.back_knifes_num = this.knifes.length;
        for (var i = t; i >= 0; i--) {
            egret.Tween.get(this.knifes[i]).to({ x: p.x, y: p.y }, 300).call(function () {
                for (var j = _this.knifes.length - 1; _this.knifes.length > 0;) {
                    egret.Tween.removeTweens(_this.knifes[_this.knifes.length - 1]);
                    _this.removeKnife(_this.knifes.length - 1); //删除数组里面的刀
                }
                /**运动结束删除物体 */
                if (_this.knifes.length == 0) {
                    _this.state = PLAYERSTATE.CRUISE;
                    _this.removeChild(_this.con);
                }
            }, this);
        }
    };
    /**通过tween动画把刀发射出去 */ //暂时没用
    Player.prototype.atk = function (rotation) {
        // let hu = rotation * Math.PI / 180;
        // let a = 200 * Math.sin(hu);
        // let b = 200 * Math.cos(hu);
        // let x = this.con.x + a;
        // let y = this.con.y - b;
        // //	let p = this.CheckBoun(x, y, 3);
        // let p = this.CheckBound(x, y);//控制tween动画运行时移动方向及距离
        // egret.Tween.get(this.con).to({ x: p.x, y: p.y }, 600).call(() => {
        // 	egret.Tween.removeTweens(this.con);
        // 	//运动结束删除物体
        // 	this.state = PLAYERSTATE.CRUISE;
        // 	this.removeChild(this.con);
        // 	for (let i = 3; this.knifes.length > 0; i--) {
        // 		this.removeKnife(i);
        // 	}
        // 	console.log(this.knifes.length);
        // }, this);
    };
    Player.prototype.CheckBound = function (x, y) {
        // if (x + this.x > DesignConst.mapwidth) {
        // 	x = DesignConst.mapwidth - this.x - 100;
        // }
        // if (y + this.y > DesignConst.mapheight) {
        // 	y = DesignConst.mapheight - this.y - 100;
        // }
        // if (x + this.x < 0) {
        // 	x = this.x + (x - (this.x + x));
        // }
        // if (y + this.y < 0) {
        // 	y = this.y + (y - (this.y + y));
        // }
        return new egret.Point(x, y);
    };
    Player.prototype.addCircle = function () {
        var bmp = ObjectPool.getObject("BaseBitmap");
        var r = Math.floor(Math.random() * 5 + 1);
        //bmp.texture = RES.getRes("yuan_" + r);
        this.addChildAt(bmp, 0);
        bmp.width = this.bg_diameter;
        bmp.height = this.bg_diameter;
        bmp.anchorOffsetX = this.vo.circleRadius;
        bmp.anchorOffsetY = this.vo.circleRadius;
        var s = 2.4;
        egret.Tween.get(bmp).to({ scaleX: s, scaleY: s, alpha: 0 }, 1200).call(function (bmp) {
            if (bmp != null && bmp.parent != null) {
                bmp.parent.removeChild(bmp);
            }
        }, this, [bmp]);
    };
    //没有被调用
    Player.prototype.addKnifeNum = function (n) {
        // this.vo.knife_num += n;
        // this.updateKnifes();
    };
    /**碰撞后删除飞刀*/
    Player.prototype.removeKnife = function (i) {
        var knife = this.knifes[i];
        if (knife != null) {
            this.vo.knife_num--;
            this.knifes.splice(i, 1);
            if (knife.parent != null) {
                knife.parent.removeChild(knife);
            }
        }
    };
    /**获取到捡起飞刀数量并调动生成身上飞刀方法 */
    Player.prototype.checkEatKnife = function () {
        var n = Maplogic.getInstance().dealEatKnifes(this.x, this.y, this.vo.radius);
        //判断是否接触到飞刀，玩家身上飞刀数量是否超过5把
        if (n > 0) 
        //if (n > 0 && this.vo.knife_num <= 4) 
        {
            this.vo.knife_num += n;
            this.updateKnifes();
        }
    };
    Player.prototype.updateView = function () {
        this.updateBg();
        this.updateLblName();
    };
    /**删除地上飞刀后在玩家身上生成新的飞刀 */
    Player.prototype.updateKnifes = function () {
        //let n= Maplogic.getInstance().dealEatKnifes(this.x, this.y, this.vo.radius);
        this.b = this.back_knifes_num;
        //console.log(this.b + "身上刀数量");
        this.n = this.vo.knife_num;
        if (this.n > this.b) {
            this.b = this.n - this.b + this.b;
        }
        //判断玩家飞刀数量是否大于5，若大于则N等于5
        if (this.b >= DesignConst.player_knife_max) {
            this.b = DesignConst.player_knife_max;
        }
        if (this.state == PLAYERSTATE.CRUISE || this.state == PLAYERSTATE.WAIT) {
            var knife_height = 115;
            this.vo.radius = knife_height * this.n / 2 / Math.PI;
        }
        else {
            this.vo.radius = 115 * this.n / 2 / Math.PI;
        }
        for (var i = 0; i < this.b; i++) {
            var v = this.vo.skinvo;
            var knife = this.knifes[i];
            if (knife == null) {
                knife = ObjectPool.getObject("BaseBitmap");
                knife.texture = RES.getRes("dao_" + 3);
                knife.scaleX = knife.scaleY = DesignConst.knifescale;
                knife.anchorOffsetX = knife.width / 2;
                knife.state = KNIFESTATE.FLYING;
                if (this.state == PLAYERSTATE.DEFENCE) {
                    knife.anchorOffsetY = -this.vo.circleRadius / 2 + knife.height;
                }
                else {
                    knife.anchorOffsetY = -this.vo.radius + knife.height;
                }
                if (this.ss == false) {
                    this.vo.knife_num++;
                }
                this.knifes.push(knife);
            }
            this.con.addChild(knife);
        }
        this.back_knifes_num = 0;
    };
    /**刀状态调整 */
    Player.prototype.updateKnifeInArr = function (i) {
        var knife = this.knifes[i];
        if (knife != null) {
            //声明一个变量n继承刀这个变量
            var n = this.vo.knife_num;
            //如果n大于等于刀的总数
            if (n >= DesignConst.player_knife_max) {
                //n=刀的总数
                n = DesignConst.player_knife_max;
            }
            if (this.state == PLAYERSTATE.CRUISE || this.state == PLAYERSTATE.WAIT) {
                var knife_height = 180;
                if (this.vo.knife_num < 5) {
                    this.vo.radius = knife_height * 4 / 2 / Math.PI;
                }
                else {
                    this.vo.radius = knife_height * n / 2 / Math.PI;
                }
            }
            /**刀状态调整 */
            if (this.state == PLAYERSTATE.DEFENCE) {
                knife.anchorOffsetY = knife.height / 2;
                if (this.vo.knife_num == 1) {
                    knife.anchorOffsetX = 2 * (this.vo.radius + knife.width / 2) / DesignConst.knifescale;
                }
                else if (this.vo.knife_num == 2) {
                    knife.anchorOffsetX = 1.5 * (this.vo.radius + knife.width / 2) / DesignConst.knifescale;
                }
                else if (this.vo.knife_num > 5) {
                    knife.anchorOffsetX = ((180 * 4 / 2 / Math.PI) + knife.width / 2) / DesignConst.knifescale;
                }
                else {
                    knife.anchorOffsetX = (this.vo.radius + knife.width / 2) / DesignConst.knifescale;
                }
                if (this.vo.knife_num == 2) {
                    knife.rotation = 180 * i / 3;
                }
                else {
                    knife.rotation = 180 * i / n;
                }
                knife.scaleX = 1;
                /**刀容器的角度跟随鼠标角度 */
                this.con.rotation = this.vo.Rightdirection;
            }
            if (this.state == PLAYERSTATE.CRUISE || this.state == PLAYERSTATE.WAIT) {
                knife.anchorOffsetX = -this.vo.circleRadius / 2 - knife.height / 2; //刀离玩家的距离
                knife.anchorOffsetY = knife.width / 2;
                if (this.vo.knife_num == 2 || this.vo.knife_num == 3) {
                    knife.rotation = 180 * i / 4;
                }
                else {
                    knife.rotation = 180 * i / n;
                }
                knife.scaleX = -1; //镜像反转			
            }
            if (this.state == PLAYERSTATE.ATK && knife.state == KNIFESTATE.FLYING) {
                knife.anchorOffsetX = knife.width / 2;
                knife.anchorOffsetY = knife.height / 2;
                knife.rotation = this.jiao - 180;
                //左右移动
                if (this.jiao > 67.5 && this.jiao < 112.5) {
                    knife.x = this.vo.radius;
                    knife.y = -75 + 45 * i;
                }
                if (this.jiao < -67.5 || this.jiao > 247.5) {
                    knife.x = -this.vo.radius;
                    knife.y = -75 + 45 * i;
                }
                //上下移动
                if (this.jiao > -22.5 && this.jiao < 22.5) {
                    knife.x = -75 + 45 * i;
                    knife.y = -this.vo.radius;
                }
                if (this.jiao < 202.5 && this.jiao > 157.5) {
                    knife.x = -75 + 45 * i;
                    knife.y = this.vo.radius;
                }
                //右下左上
                if (this.jiao < 157.5 && this.jiao > 112.5) {
                    knife.x = 75 - 45 * i;
                    knife.y = -75 + 45 * i;
                }
                if (this.jiao < -22.5 && this.jiao > -67.5) {
                    knife.x = 75 - 45 * i;
                    knife.y = -75 + 45 * i;
                }
                //右上左下
                if (this.jiao < 67.5 && this.jiao > 22.5) {
                    knife.x = -75 + 45 * i;
                    knife.y = -75 + 45 * i;
                }
                if (this.jiao < 247.5 && this.jiao > 202.5) {
                    knife.x = -75 + 45 * i;
                    knife.y = -75 + 45 * i;
                }
                knife.state = KNIFESTATE.BULLET;
            }
        }
    };
    Player.prototype.updateBg = function () {
        this.bg_diameter = this.vo.circleRadius * 2;
        this.bg.width = this.bg_diameter;
        this.bg.height = this.bg_diameter;
        this.bg.anchorOffsetX = this.vo.circleRadius;
        this.bg.anchorOffsetY = this.vo.circleRadius;
    };
    Player.prototype.updateLblName = function () {
        this.lbl_name.size = this.vo.circleRadius < 50 ? 24 : 32;
        this.lbl_name.width = this.bg_diameter;
        this.lbl_name.anchorOffsetX = this.lbl_name.width / 2;
        this.lbl_name.anchorOffsetY = this.lbl_name.height / 2;
    };
    Player.prototype.updateRadius = function () {
    };
    Player.prototype.clear = function () {
    };
    Player.prototype.reset = function () {
    };
    Player.prototype.destroy = function () {
    };
    return Player;
}(egret.DisplayObjectContainer));
__reflect(Player.prototype, "Player", ["IPool"]);
window['Player'] = Player;
var UIConst = (function () {
    function UIConst() {
    }
    /** rubbish */
    UIConst.s1 = "a5b684c3afbc";
    UIConst.s2 = "4026b";
    return UIConst;
}());
__reflect(UIConst.prototype, "UIConst");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var ThemeAdapter = (function () {
    function ThemeAdapter() {
    }
    /**
     * 解析主题
     * @param url 待解析的主题url
     * @param onSuccess 解析完成回调函数，示例：compFunc(e:egret.Event):void;
     * @param onError 解析失败回调函数，示例：errorFunc():void;
     * @param thisObject 回调的this引用
     */
    ThemeAdapter.prototype.getTheme = function (url, onSuccess, onError, thisObject) {
        var _this = this;
        function onResGet(e) {
            onSuccess.call(thisObject, e);
        }
        function onResError(e) {
            if (e.resItem.url == url) {
                RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                onError.call(thisObject);
            }
        }
        if (typeof generateEUI !== 'undefined') {
            egret.callLater(function () {
                onSuccess.call(thisObject, generateEUI);
            }, this);
        }
        else if (typeof generateEUI2 !== 'undefined') {
            RES.getResByUrl("resource/gameEui.json", function (data, url) {
                window["JSONParseClass"]["setData"](data);
                egret.callLater(function () {
                    onSuccess.call(thisObject, generateEUI2);
                }, _this);
            }, this, RES.ResourceItem.TYPE_JSON);
        }
        else if (typeof generateJSON !== 'undefined') {
            if (url.indexOf(".exml") > -1) {
                var dataPath = url.split("/");
                dataPath.pop();
                var dirPath = dataPath.join("/") + "_EUI.json";
                if (!generateJSON.paths[url]) {
                    RES.getResByUrl(dirPath, function (data) {
                        window["JSONParseClass"]["setData"](data);
                        egret.callLater(function () {
                            onSuccess.call(thisObject, generateJSON.paths[url]);
                        }, _this);
                    }, this, RES.ResourceItem.TYPE_JSON);
                }
                else {
                    egret.callLater(function () {
                        onSuccess.call(thisObject, generateJSON.paths[url]);
                    }, this);
                }
            }
            else {
                egret.callLater(function () {
                    onSuccess.call(thisObject, generateJSON);
                }, this);
            }
        }
        else {
            RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
            RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
        }
    };
    return ThemeAdapter;
}());
__reflect(ThemeAdapter.prototype, "ThemeAdapter", ["eui.IThemeAdapter"]);
//刀的基类
var BaseBitmap = (function (_super) {
    __extends(BaseBitmap, _super);
    function BaseBitmap() {
        return _super.call(this) || this;
    }
    BaseBitmap.prototype.reset = function () {
        this.texture = null;
        this.width = 0;
        this.height = 0;
        this.alpha = 1;
        this.rotation = 0;
        this.anchorOffsetX = 0;
        this.anchorOffsetY = 0;
        this.scaleX = 1;
        this.scaleY = 1;
        this.state = 1;
    };
    BaseBitmap.prototype.clear = function () { };
    BaseBitmap.prototype.destroy = function () { };
    return BaseBitmap;
}(egret.Bitmap));
__reflect(BaseBitmap.prototype, "BaseBitmap", ["IPool"]);
//可能情况1：window数组中一个叫BaseBitmap的元素等于这个类
window['BaseBitmap'] = BaseBitmap;
var BaseTextField = (function (_super) {
    __extends(BaseTextField, _super);
    function BaseTextField() {
        return _super.call(this) || this;
    }
    BaseTextField.prototype.reset = function () {
        this.text = "";
        this.width = null;
        this.height = null;
        this.anchorOffsetX = 0;
        this.anchorOffsetY = 0;
    };
    BaseTextField.prototype.destroy = function () { };
    BaseTextField.prototype.clear = function () { };
    return BaseTextField;
}(egret.TextField));
__reflect(BaseTextField.prototype, "BaseTextField", ["IPool"]);
window['BaseTextField'] = BaseTextField;
var GameData = (function () {
    function GameData() {
    }
    return GameData;
}());
__reflect(GameData.prototype, "GameData");
var GameEvent = (function (_super) {
    __extends(GameEvent, _super);
    function GameEvent(type, bubbles, cancelable) {
        if (bubbles === void 0) { bubbles = false; }
        if (cancelable === void 0) { cancelable = false; }
        var _this = _super.call(this, type, bubbles, cancelable) || this;
        _this.data = null;
        return _this;
    }
    GameEvent.REWARDAD_CLOSE_EVENT = "REWARDAD_CLOSE_EVENT";
    return GameEvent;
}(egret.Event));
__reflect(GameEvent.prototype, "GameEvent");
/**
 *
 * @author
 *
 */
var SoundManager = (function () {
    function SoundManager() {
        this.bg_position = 0;
        this.sound_switch = true;
        this.sound_effect_switch = false;
    }
    SoundManager.getInstance = function () {
        if (this.instance == null) {
            this.instance = new SoundManager();
        }
        return this.instance;
    };
    /**打开/关闭背景音乐*/
    SoundManager.prototype.playBgSound = function (b) {
        this.sound_switch = b;
        if (b) {
            if (this.bgSound == null) {
                this.bgSound = RES.getRes("bgm_1_mp3");
            }
            if (this.bgChannel != null) {
                this.bgChannel.stop();
                this.bgChannel = null;
            }
            this.bgChannel = this.bgSound.play(this.bg_position, 0);
        }
        else {
            if (this.bgChannel != null) {
                this.bg_position = this.bgChannel.position;
                this.bgChannel.stop();
                this.bgChannel = null;
            }
            else {
                this.bg_position = 0;
            }
        }
    };
    SoundManager.prototype.hideSound = function (b) {
        if (b) {
            if (this.sound_switch) {
                if (this.bgSound == null) {
                    this.bgSound = RES.getRes("bgm_1_mp3");
                }
                if (this.bgChannel != null) {
                    this.bgChannel.stop();
                    this.bgChannel = null;
                }
                this.bgChannel = this.bgSound.play(this.bg_position, 0);
                this.bg_position = 0;
            }
        }
        else {
            if (this.bgChannel != null) {
                this.bg_position = this.bgChannel.position;
                this.bgChannel.stop();
                this.bgChannel = null;
            }
            else {
                this.bg_position = 0;
            }
        }
    };
    /**音效开关*/
    SoundManager.prototype.setSoundEffectSwitch = function (b) {
        this.sound_effect_switch = b;
    };
    /**播放音效*/
    SoundManager.prototype.playEffectSound = function (str) {
        if (str === void 0) { str = "sound_11_wav"; }
        console.log("playEffectSound:", this.sound_effect_switch);
        if (!this.sound_switch) {
            return;
        }
        var sound = RES.getRes(str);
        if (sound != null) {
            var channel = sound.play(0, 1);
            var obj = { s: sound, c: channel };
            var complete = function () {
                this.c.stop();
                this.c = null;
                this.s = null;
            };
            channel.addEventListener(egret.Event.SOUND_COMPLETE, complete, obj);
        }
    };
    return SoundManager;
}());
__reflect(SoundManager.prototype, "SoundManager");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var AssetAdapter = (function () {
    function AssetAdapter() {
    }
    /**
     * @language zh_CN
     * 解析素材
     * @param source 待解析的新素材标识符
     * @param compFunc 解析完成回调函数，示例：callBack(content:any,source:string):void;
     * @param thisObject callBack的 this 引用
     */
    AssetAdapter.prototype.getAsset = function (source, compFunc, thisObject) {
        function onGetRes(data) {
            compFunc.call(thisObject, data, source);
        }
        if (RES.hasRes(source)) {
            var data = RES.getRes(source);
            if (data) {
                onGetRes(data);
            }
            else {
                RES.getResAsync(source, onGetRes, this);
            }
        }
        else {
            RES.getResByUrl(source, onGetRes, this, RES.ResourceItem.TYPE_IMAGE);
        }
    };
    return AssetAdapter;
}());
__reflect(AssetAdapter.prototype, "AssetAdapter", ["eui.IAssetAdapter"]);
var GameUtil = (function () {
    function GameUtil() {
    }
    /**灰色滤镜*/
    GameUtil.getGrayFilter = function () {
        var colorMatrix = [
            0.3, 0.6, 0, 0, 0,
            0.3, 0.6, 0, 0, 0,
            0.3, 0.6, 0, 0, 0,
            0, 0, 0, 1, 0
        ];
        var colorFlilter = new egret.ColorMatrixFilter(colorMatrix);
        return [colorFlilter];
    };
    /**根据2个坐标点获取角度 */
    GameUtil.getRotation = function (src, tar) {
        var dy = Math.abs(src.y - tar.y);
        var dx = Math.abs(src.x - tar.x);
        var r = Math.atan2(dx, dy) * 180 / Math.PI;
        if (tar.x > src.x) {
            if (tar.y < src.y) {
                r = r + 0;
            }
            else {
                r = 180 - r;
            }
        }
        else {
            if (tar.y < src.y) {
                r = 360 - r;
            }
            else {
                r = 180 + r;
            }
        }
        return r;
    };
    /** 根据权重随机 */
    GameUtil.getRandomByWeight = function (arr) {
        var total = 0;
        for (var i = 0; i < arr.length; i++) {
            total += arr[i];
        }
        var r = Math.floor(Math.random() * total);
        var index = 0;
        for (var i = 0; i < arr.length; i++) {
            if (i > 0) {
                r -= arr[i - 1];
            }
            if (r < arr[i]) {
                index = i;
                break;
            }
        }
        return index;
    };
    /**tip提示 */
    GameUtil.showMessage = function (str) {
        console.log("showMessage:", str);
    };
    /**给按钮做连续点击检测
     * @param btn 点击的按钮
     * @param delay 按钮连续点击间隔，delay间隔内不能连续点击
     * @return true 可以点击
     */
    GameUtil.CheckBtnContinuousClick = function (btn, delay) {
        if (delay === void 0) { delay = 1; }
        if (this.btnTimeDic == null) {
            this.btnTimeDic = {};
        }
        var key = btn.hashCode;
        var last = this.btnTimeDic[key];
        var now = new Date().getTime();
        var b = last == null || now - last > delay * 1000;
        if (b) {
            this.btnTimeDic[key] = now;
        }
        return b;
    };
    /**
     * @param
     * @param
     * @param floor 0不处理  1floor -1ceil 2[a,b]双闭区间，整数
     */
    GameUtil.between = function (a, b, floor) {
        if (floor === void 0) { floor = 2; }
        var r = Math.random() * (b - a) + a;
        if (floor == 0) {
            return r;
        }
        else if (floor == 1) {
            return Math.floor(r);
        }
        else if (floor == -1) {
            return Math.ceil(r);
        }
        else {
            return Math.floor(Math.random() * (b - a + 1) + a);
        }
    };
    /**对数组乱序 */
    GameUtil.shuffle = function (a) {
        var b = a.slice();
        var c = [];
        while (true) {
            var i = Math.floor(Math.random() * b.length);
            c.push(b[i]);
            b.splice(i, 1);
            if (b.length == 0) {
                break;
            }
        }
        return c;
    };
    GameUtil.getShape = function (width, height, color, alpha) {
        if (width === void 0) { width = 640; }
        if (height === void 0) { height = 960; }
        if (color === void 0) { color = 0x000000; }
        if (alpha === void 0) { alpha = 0.7; }
        var shp = new egret.Shape();
        shp.graphics.beginFill(color, alpha);
        shp.graphics.drawRect(0, 0, width, height);
        shp.graphics.endFill();
        shp.touchEnabled = false;
        return shp;
    };
    GameUtil.getRectShape = function (width, height, color, alpha, ellipseWidth, ellipseHeight) {
        if (width === void 0) { width = 640; }
        if (height === void 0) { height = 960; }
        if (color === void 0) { color = 0x000000; }
        if (alpha === void 0) { alpha = 0.7; }
        if (ellipseWidth === void 0) { ellipseWidth = 0; }
        if (ellipseHeight === void 0) { ellipseHeight = 0; }
        var shp = new egret.Shape();
        shp.graphics.beginFill(color, alpha);
        shp.graphics.drawRoundRect(0, 0, width, height, ellipseWidth, ellipseHeight);
        shp.graphics.endFill();
        shp.touchEnabled = false;
        return shp;
    };
    /**把一个数字转换
     * @param n 原始数字
     * @param s 10的s次幂
     */
    GameUtil.dealNum = function (n, s) {
        if (s === void 0) { s = 3; }
        var ss = Math.pow(10, s);
        return Math.round(n / ss);
    };
    /**
     * 倒计时转换为时间格式（h:m:s） ，可自定义
     * @param t 秒
     * @param f 格式
     */
    GameUtil.ParseTime2Format = function (t, f) {
        if (f === void 0) { f = "h:m:s"; }
        var d = Math.floor(t / 24 / 3600);
        var h = Math.floor((t / 3600) % 24);
        var m = Math.floor((t % 3600) / 60);
        var s = (t % 3600) % 60;
        function parse_format(t) {
            var s = t.toString();
            if (t < 10) {
                s = "0" + t;
            }
            return s;
        }
        if (f.indexOf("d") != -1) {
            f = f.replace(/d/g, parse_format(d));
        }
        else {
            h += d * 24;
        }
        if (f.indexOf("h") != -1) {
            f = f.replace(/h/g, parse_format(h));
        }
        else {
            m += h * 60;
        }
        if (f.indexOf("m") != -1) {
            f = f.replace(/m/g, parse_format(m));
        }
        else {
            if (f.indexOf("h") != -1) {
                s += m * 60;
            }
            else {
                s = t;
            }
        }
        if (f.indexOf("s") != -1) {
            f = f.replace(/s/g, parse_format(s));
        }
        return f;
    };
    /**创建文本
     * @param x 如果为
     * @param y
     * @param pw 如果为null  设置x  否则 x=(pw-w)/2
     * @param ph 如果为null  设置y  否则 y=(ph-h)/2
     */
    GameUtil.createTextField = function (x, y, pw, ph, w, h, color, size, font, textalign, veralign) {
        if (color === void 0) { color = 0xffffff; }
        if (size === void 0) { size = 30; }
        if (font === void 0) { font = "SimHei"; }
        if (textalign === void 0) { textalign = "center"; }
        if (veralign === void 0) { veralign = "middle"; }
        var tf = new egret.TextField();
        if (x != null) {
            tf.x = x;
        }
        if (y != null) {
            tf.y = y;
        }
        if (pw != null) {
            tf.x = (pw - w) / 2;
        }
        if (ph != null) {
            tf.y = (ph - h) / 2;
        }
        if (w != null) {
            tf.width = w;
        }
        if (h != null) {
            tf.height = h;
        }
        tf.textColor = color;
        tf.size = size;
        tf.fontFamily = font;
        tf.textAlign = textalign;
        tf.verticalAlign = veralign;
        tf.touchEnabled = false;
        return tf;
    };
    /**创建图片
     * @param res 资源名
     * @param x 如果不为null，则设置为x
     * @param y 如果不为null，则设置为y
     * @param pw 如果为null  设置x  否则 x=(pw-w)/2
     * @param ph 如果为null  设置y  否则 y=(ph-h)/2
     * @param center 锚点 默认0左上角
     * @param w 图片宽 默认初始宽度
     * @param h 图片高 默认初始高度
    
     */
    GameUtil.createBitmap = function (res, x, y, pw, ph, center, w, h) {
        if (x === void 0) { x = 0; }
        if (y === void 0) { y = 0; }
        if (pw === void 0) { pw = null; }
        if (ph === void 0) { ph = null; }
        if (center === void 0) { center = 0; }
        if (w === void 0) { w = null; }
        if (h === void 0) { h = null; }
        var bmp = new egret.Bitmap();
        if (res != null) {
            bmp.texture = RES.getRes(res);
        }
        if (w != null) {
            bmp.width = w;
        }
        if (h != null) {
            bmp.height = h;
        }
        if (center % 3 == 1) {
            bmp.anchorOffsetX = bmp.width / 2;
        }
        else if (center % 3 == 2) {
            bmp.anchorOffsetX = bmp.width;
        }
        var i = Math.floor(center / 3);
        if (i == 1) {
            bmp.anchorOffsetY = bmp.height / 2;
        }
        else if (i == 2) {
            bmp.anchorOffsetY = bmp.height;
        }
        if (x != null) {
            bmp.x = x;
        }
        if (y != null) {
            bmp.y = y;
        }
        if (pw != null) {
            bmp.x = (pw - w) / 2;
        }
        if (ph != null) {
            bmp.y = (ph - h) / 2;
        }
        return bmp;
    };
    /**名字太长改为xxx.. */
    GameUtil.formatNameString = function (str) {
        var len = 0;
        var newstr = "";
        for (var i = 0; i < str.length; i++) {
            if (str.charCodeAt(i) > 127 || str.charCodeAt(i) == 94) {
                len += 2;
            }
            else {
                len++;
            }
            newstr += str.charAt(i);
            if (len > 12 && i < str.length - 1) {
                return newstr + "..";
            }
        }
        return str;
    };
    /**处理一些特殊字符导致的无法显示的名字 */
    GameUtil.checkSpeName = function (str) {
        var newstr = "";
        var i = 0;
        while (i < str.length) {
            var n = str.charCodeAt(i);
            var s = str.charAt(i);
            i++;
            if (n >= 65024 && n <= 65039) {
                continue;
            }
            newstr += s;
        }
        return newstr;
    };
    /**把一个DisObject画成一个位图
    * @param disobject 要画的disobject
    * @param scale 缩放比例
    */
    GameUtil.drawBitmapFromDisObject = function (disobject, clipBounds, scale) {
        var renderTexture = new egret.RenderTexture();
        renderTexture.drawToTexture(disobject, clipBounds, scale);
        var bitmap = new egret.Bitmap(renderTexture);
        return bitmap;
    };
    return GameUtil;
}());
__reflect(GameUtil.prototype, "GameUtil");
var ObjectPool = (function () {
    function ObjectPool() {
    }
    ObjectPool.returnItem = function (classType, item) {
        if (item == null)
            return;
        var list;
        if (!this.pools.hasOwnProperty(classType)) {
            list = [];
            this.pools[classType] = list;
        }
        else {
            list = this.pools[classType];
        }
        item.reset();
        if (list.indexOf(item) >= 0) {
            console.warn("return objcet error: have same object type " + classType + "?");
            return;
        }
        list.push(item);
    };
    /**
     *Get one item from pool
     * @param classType：
     * @return
     *
     */
    ObjectPool.getObject = function (classType) {
        var poolList;
        //hasOwnProperty()方法返回一个布尔值，判断对象是否包含特定的自身（非继承）属性。
        if (!this.pools.hasOwnProperty(classType)) {
            poolList = [];
            this.pools[classType] = poolList;
        }
        else {
            poolList = this.pools[classType];
        }
        if (poolList.length > 0) {
            //list.shift() 方法用于把数组的第一个元素从其中删除，并返回第一个元素的值。
            return poolList.shift();
        }
        var obj_class = egret.getDefinitionByName(classType);
        if (obj_class == null) {
            console.error("ObjectPool:" + "\"" + classType + "\"" + " not found please check!!!");
            return;
        }
        var obj = new obj_class();
        if (obj == null) {
            console.error("getObject:" + "\"" + classType + "\"" + " is  not a IPool  children!! please check!!!");
            return;
        }
        return obj;
    };
    //dictionary
    ObjectPool.pools = new Object();
    return ObjectPool;
}());
__reflect(ObjectPool.prototype, "ObjectPool");
var ObjectUtil = (function () {
    function ObjectUtil() {
    }
    //删除所有数据
    ObjectUtil.delObjectProp = function (o) {
        for (var key in o) {
            delete o[key];
        }
    };
    //清除数据
    ObjectUtil.clearObjectProp = function (o) {
        for (var key in o) {
            o[key] = null;
        }
    };
    ObjectUtil.cloneObject = function (o) {
        var str = egret.getQualifiedClassName(o);
        var objClass = egret.getDefinitionByName(str);
        var obj = new objClass();
        if (str == "function") {
            return obj.constructor;
        }
        for (var k in o) {
            if (k == "callBackList") {
                continue;
            }
            if (k == "function") {
                return;
            }
            var value = o[k];
            if (typeof (value) == "number" ||
                typeof (value) == "string" ||
                typeof (value) == "boolean") {
                obj[k] = value;
            }
            else {
                var str = egret.getQualifiedClassName(value);
                if (str == "") {
                    continue;
                }
                obj[k] = this.cloneObject(value);
            }
        }
        return obj;
    };
    /**
     * 获取状态位
     * @param result  结果 值
     * @param crtV    当前值
     * @ return   Boolean  返回状态
     */
    ObjectUtil.getState = function (result, crtV) {
        var boo = false;
        if ((1 << crtV) & result) {
            boo = true;
        }
        return boo;
    };
    /**
     * 将num 左移 bit位。
     */
    ObjectUtil.push_bit = function (num, bit) {
        return num << bit;
    };
    return ObjectUtil;
}());
__reflect(ObjectUtil.prototype, "ObjectUtil");
var TimeUtil = (function () {
    function TimeUtil() {
    }
    /** 判断这个时间是否是今天
     * @param t 时间 秒
     */
    TimeUtil.checkToday = function (t) {
        var today0 = Math.floor(TimeUtil.getTodayZero() / 1000);
        return t >= today0;
    };
    /** 获取今日的0点的时间
     * @return 毫秒
    */
    TimeUtil.getTodayZero = function () {
        var d = new Date();
        var h = d.getHours();
        var m = d.getMinutes();
        var s = d.getSeconds();
        var secs = h * 3600 + m * 60 + s;
        return d.getTime() - secs * 1000;
    };
    /**
     * 返回一年中的第N天
     * @param t 秒
     */
    TimeUtil.GetDayInYear = function (t) {
        var time = new Date(t);
        var month = time.getMonth() + 1;
        var year = time.getFullYear();
        var days = time.getDate();
        var sum = 0;
        var a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            for (var i = 0; i < month - 1; i++) {
                sum += b[i];
            }
            return sum + days;
        }
        else {
            for (var i = 0; i < month - 1; i++) {
                sum += a[i];
            }
            return sum + days;
        }
    };
    /**
     * 返回时间点在当天的秒数
     */
    TimeUtil.getSecondInDay = function (date) {
        return date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds();
    };
    /**
     * 倒计时转换为时间格式（h:m:s） ，可自定义
     * @param t 秒
     * @param f 格式
     */
    TimeUtil.ParseTime2Format = function (t, f) {
        if (f === void 0) { f = "h:m:s"; }
        var d = Math.floor(t / 24 / 3600);
        var h = Math.floor((t / 3600) % 24);
        var m = Math.floor((t % 3600) / 60);
        var s = (t % 3600) % 60;
        function parse_format(t) {
            var s = t.toString();
            if (t < 10) {
                s = "0" + t;
            }
            return s;
        }
        if (f.indexOf("d") != -1) {
            f = f.replace(/d/g, parse_format(d));
        }
        else {
            h += d * 24;
        }
        if (f.indexOf("h") != -1) {
            f = f.replace(/h/g, parse_format(h));
        }
        else {
            m += h * 60;
        }
        if (f.indexOf("m") != -1) {
            f = f.replace(/m/g, parse_format(m));
        }
        else {
            if (f.indexOf("h") != -1) {
                s += m * 60;
            }
            else {
                s = t;
            }
        }
        if (f.indexOf("s") != -1) {
            f = f.replace(/s/g, parse_format(s));
        }
        return f;
    };
    /**
     * 转换为日期格式
     * @param t 毫秒
     * @param f 格式 Y/M/D h:m:s
     */
    TimeUtil.ParseTime2Date = function (t, f) {
        if (f === void 0) { f = "Y-M-D h:m:s"; }
        var d = new Date(t);
        var Y = d.getFullYear();
        var M = d.getMonth() + 1;
        var D = d.getDate();
        var h = d.getHours();
        var m = d.getMinutes();
        var s = d.getSeconds();
        function parse_format(t) {
            var s = t.toString();
            if (t < 10) {
                s = "0" + t;
            }
            return s;
        }
        if (f.indexOf("Y") != -1) {
            f = f.replace(/Y/g, parse_format(Y));
        }
        if (f.indexOf("M") != -1) {
            f = f.replace(/M/g, parse_format(M));
        }
        if (f.indexOf("D") != -1) {
            f = f.replace(/D/g, parse_format(D));
        }
        if (f.indexOf("h") != -1) {
            f = f.replace(/h/g, parse_format(h));
        }
        if (f.indexOf("m") != -1) {
            f = f.replace(/m/g, parse_format(m));
        }
        if (f.indexOf("s") != -1) {
            f = f.replace(/s/g, parse_format(s));
        }
        return f;
    };
    /**
     * 将时间转换为天/小时/分钟/秒
     * @param t 秒
     */
    TimeUtil.ParseTimeChangeToUtil = function (t) {
        var str = "";
        if (t >= 3600 * 24) {
            str = Math.floor(t / (3600 * 24)) + "天";
        }
        else if (t >= 3600) {
            str = Math.floor(t / 3600) + "小时";
        }
        else if (t >= 60) {
            str = Math.floor(t / 60) + "分钟";
        }
        else if (t < 60 && t > 0) {
            str = t + "秒";
        }
        return str;
    };
    /**
     * 获得带单位的时间字符串
     * * @param t 秒
     * @param f 格式 "d" "h" "m" "s"
     */
    TimeUtil.ParseTime2Units = function (t, f) {
        if (f === void 0) { f = "h"; }
        var str = "";
        if (f == "d") {
            str = Math.ceil(t / (3600 * 24)) + "天";
        }
        else if (f == "h") {
            str = Math.ceil(t / 3600) + "小时";
        }
        else if (f == "m") {
            str = Math.ceil(t / 60) + "分钟";
        }
        else if (f == "s") {
            str = t + "秒";
        }
        else {
            var d = Math.floor(t / (3600 * 24));
            var h = Math.floor(t / 3600);
            var m = Math.floor(t / 60);
            var s = t % 60;
            str = d + "天" + h + "时" + m + "分" + s + "秒";
        }
        return str;
    };
    /**
     * 注册倒计时
     * @param fun 回调
     * @param reg 域
     * @param tim 延时
     * @param rep 次数
     */
    TimeUtil.CreateCD = function (fun, reg, tim, rep) {
        if (rep === void 0) { rep = 0; }
        var t = new egret.Timer(tim, rep);
        t.addEventListener(egret.TimerEvent.TIMER, fun, reg);
        return t;
    };
    TimeUtil.RemoveCD = function (tim, fun, reg) {
        if (tim != null) {
            tim.stop();
            tim.removeEventListener(egret.TimerEvent.TIMER, fun, reg);
        }
    };
    return TimeUtil;
}());
__reflect(TimeUtil.prototype, "TimeUtil");
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.isdebug = function () {
        return true;
    };
    DebugPlatform.prototype.checkUpdate = function () {
        return;
    };
    DebugPlatform.prototype.getUserInfo = function (h) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "skybear", gender: 1, avatarUrl: "" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { code: "debug_logincode" }];
            });
        });
    };
    DebugPlatform.prototype.initmta = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.mtaLoad = function (id, data) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.share = function (title, imageUrl, query) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.createGameClubButton = function (left, top, w, h) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.vibrate = function (short) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.createRewardedVideoAd = function (obj) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, null];
            });
        });
    };
    DebugPlatform.prototype.bannershow = function (id, h) {
        return;
    };
    DebugPlatform.prototype.bannerdestroy = function () {
        return;
    };
    DebugPlatform.prototype.bannerhide = function () {
        return;
    };
    DebugPlatform.prototype.bannerError = function () {
        return;
    };
    DebugPlatform.prototype.getSystemInfoSync = function () {
        return { screenWidth: 750, screenHeight: 1334 };
    };
    DebugPlatform.prototype.createUserButton = function (h) {
        return;
    };
    DebugPlatform.prototype.hideClubButton = function () {
        return;
    };
    DebugPlatform.prototype.showClubButton = function () {
        return;
    };
    DebugPlatform.prototype.destroyClubButton = function () {
        return;
    };
    DebugPlatform.prototype.createFeedback = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.feedbackShow = function () {
        return;
    };
    DebugPlatform.prototype.feedbackDestroy = function () {
        return;
    };
    DebugPlatform.prototype.feedbackHide = function () {
        return;
    };
    DebugPlatform.prototype.getMenuButtonBoundingClientRect = function (w, h) {
        return { top: 48, width: 64, height: 64 };
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
/**
 * 用户信息
 *
 */
var UserInfo = (function () {
    function UserInfo() {
        /** 是否授权 */
        this.auth = false;
    }
    return UserInfo;
}());
__reflect(UserInfo.prototype, "UserInfo");
var WxApi = (function (_super) {
    __extends(WxApi, _super);
    function WxApi() {
        return _super.call(this) || this;
    }
    WxApi.getInstance = function () {
        if (this._instance == null) {
            this._instance = new WxApi();
        }
        return this._instance;
    };
    WxApi.prototype.onShow = function () {
        if (platform.isdebug()) {
            return;
        }
    };
    WxApi.prototype.offShow = function () {
        if (platform.isdebug()) {
            return;
        }
    };
    WxApi.prototype.init = function () {
        return __awaiter(this, void 0, void 0, function () {
            var res, userinfo;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.inited = false;
                        return [4 /*yield*/, platform.login()];
                    case 1:
                        res = _a.sent();
                        this.logincode = res.code;
                        console.log("logincode:", res.code);
                        platform.checkUpdate();
                        this.onShare();
                        this.initRewardVideoAd();
                        userinfo = new UserInfo();
                        userinfo.avatarUrl = "";
                        userinfo.city = "";
                        userinfo.country = "";
                        userinfo.gender = 2;
                        userinfo.language = "";
                        userinfo.nickname = "玩家";
                        userinfo.province = "";
                        userinfo.auth = false;
                        this.userInfo = userinfo;
                        return [2 /*return*/];
                }
            });
        });
    };
    /** 二，得到token以后把微信的用户信息以后发给服务器 */
    WxApi.prototype.getTokenResponse = function (e) {
        if (e.data == "ioerror") {
            GameConst.save_server = false;
        }
        else if (e.data == "fail") {
            GameConst.save_server = false;
        }
        else {
            GameConst.save_server = true;
            this.userInfo.token = e.data.token;
        }
        // HttpCommand.getInstance().once(HttpEvent.getUser, this.getUserResponse, this);
        // HttpCommand.getInstance().getUser();
    };
    /** 预加载激励视频 */
    WxApi.prototype.initRewardVideoAd = function () {
        var _this = this;
        if (platform.isdebug()) {
            return;
        }
        this.rewardAd = wx.createRewardedVideoAd({ adUnitId: GameConst.rewardAdId });
        this.rewardAd.onLoad(function () {
            console.log('激励视频 广告加载成功');
        });
        this.rewardAd.onError(function (err) {
            console.log("rewardAderror:", err);
        });
        this.rewardAd.onClose(function (res) {
            // 用户点击了【关闭广告】按钮
            var state;
            // 小于 2.1.0 的基础库版本，res 是一个 undefined
            if (res && res.isEnded || res === undefined) {
                // 正常播放结束，可以下发游戏奖励
                state = 0;
                _this.rewardAdCDStart();
            }
            else {
                // 播放中途退出，不下发游戏奖励
                state = 1;
            }
            _this.dispatchGameEvent(GameEvent.REWARDAD_CLOSE_EVENT, state);
        });
    };
    /** 观看视频 关闭视频监听GameEvent.REWARDAD_CLOSE_EVENT
     * @param type 观看视频来源类型 WATCHTYPE.XXXX
     */
    WxApi.prototype.showRewardAd = function (type) {
        this.adtype = type;
        if (this.rewardAd != null) {
            try {
                this.rewardAd.show()
                    .catch(function (err) {
                    console.log("showRewardAd:", err);
                });
            }
            catch (e) {
                console.log("rewardAd:", e);
            }
        }
    };
    WxApi.prototype.rewardAdCDStart = function () {
        this.starttime = new Date().getTime();
        this.setLocalDataByString("rewardcd", this.starttime + "");
    };
    WxApi.prototype.getRewardCD = function () {
        var nowtime = new Date().getTime();
        if (this.starttime == null) {
            return 0;
        }
        else {
            return 180 - Math.floor((nowtime - this.starttime) / 1000);
        }
    };
    WxApi.prototype.dispatchGameEvent = function (eventname, data, logstr) {
        if (logstr === void 0) { logstr = "暂无视频可观看"; }
        console.log("dispatchGameEvent:", eventname, this.adtype, data);
        if (eventname == GameEvent.REWARDAD_CLOSE_EVENT && (data == 2 || data == 3)) {
            this.toast(logstr);
        }
        var event = new GameEvent(eventname);
        event.data = { type: this.adtype, data: data };
        this.dispatchEvent(event);
    };
    /**存取本地数据 */
    WxApi.prototype.setLocalDataByObject = function (key, obj) {
        var value = JSON.stringify(obj);
        this.setLocalDataByString(key, value);
    };
    /**存取本地数据 */
    WxApi.prototype.setLocalDataByString = function (key, value) {
        if (platform.isdebug()) {
            return null;
        }
        try {
            wx.setStorageSync(key, value);
        }
        catch (e) {
            return null;
        }
    };
    /**读取本地数据 */
    WxApi.prototype.getLocalData = function (key) {
        if (platform.isdebug()) {
            return null;
        }
        try {
            return wx.getStorageSync(key);
        }
        catch (e) {
            return null;
        }
    };
    /**删除缓存指定 */
    WxApi.prototype.clearLocalData = function (key) {
        if (platform.isdebug()) {
            return null;
        }
        try {
            return wx.removeStorageSync(key);
        }
        catch (e) {
            return null;
        }
    };
    WxApi.prototype.toast = function (str) {
        if (platform.isdebug()) {
            return null;
        }
        wx.showToast({
            title: str,
            icon: 'none',
            duration: 3000
        });
    };
    WxApi.prototype.share = function (type, data) {
        if (type === void 0) { type = 1; }
        if (data === void 0) { data = null; }
        if (platform.isdebug()) {
            return;
        }
        var title = "";
        var r = Math.floor(Math.random() * 3 + 1);
        var img = "resource/assets/share/share" + r + ".jpg";
        var query = "";
        switch (type) {
            case SHARETYPE.SHARE:
                title = "我飞刀玩的贼6，快来击败我";
                img = img;
                break;
            case SHARETYPE.SHOWOFF:
                title = "小李飞刀，弹无虚发";
                img = img;
                break;
        }
        wx.shareAppMessage({
            title: title,
            imageUrl: img,
            query: query
        });
    };
    /**监听用户点击右上角菜单的“转发”按钮时触发的事件
     * @param query 转发携带参数 必须是 key1=val1&key2=val2 的格式 用于区分其他用户点开这个分享链接时是否打开排行榜等操作
     */
    WxApi.prototype.onShare = function (query) {
        if (query === void 0) { query = "rightup=1"; }
        if (platform.isdebug()) {
            return;
        }
        wx.showShareMenu();
        this.updateShareMenu(true);
        wx.onShareAppMessage(function () {
            return {
                title: "小李飞刀，弹无虚发",
                imageUrl: "resource/assets/share/share1.jpg",
                query: ""
            };
        });
    };
    /**转发参数 */
    WxApi.prototype.updateShareMenu = function (withShareTicket) {
        wx.updateShareMenu({
            withShareTicket: withShareTicket,
            success: function (res) {
                console.log("updateShareMenu:success:", res);
            },
            fail: function (res) {
                console.log("updateShareMenu:fail:", res);
            },
            complete: function () {
                console.log("updateShareMenu:complete:");
            }
        });
    };
    return WxApi;
}(egret.EventDispatcher));
__reflect(WxApi.prototype, "WxApi");
/** 策划配置 */
var DesignConst = (function () {
    function DesignConst() {
    }
    /** ------------------------------ map -------------------------- */
    DesignConst.mapwidth = 2000;
    DesignConst.mapheight = 3000;
    /** ------------------------------ game -------------------------- */
    DesignConst.gametime = 120;
    DesignConst.ai_num = 5;
    /** ------------------------------ kinfe -------------------------- */
    DesignConst.knife_frest_rate = 30;
    DesignConst.knifescale = 1;
    /**地面上刷新的刀的最大值*/
    DesignConst.knife_max = 20;
    /** ------------------------------ player -------------------------- */
    /**玩家的移动速度*/
    DesignConst.role_move_speed = 5;
    /**飞刀的移动速度*/
    DesignConst.role_turn_speed = 5;
    /**AI的移动速度*/
    DesignConst.ai_move_speed = 4.5;
    /** AI飞刀的旋转速度 */
    DesignConst.ai_turn_speed = 5;
    /** 没有被调用：玩家吃进小物体 */
    DesignConst.eatSmallPlayerScale = 0.8;
    /**飞刀显示数量，数值越大，玩家身边旋转飞刀越多*/
    DesignConst.player_knife_max = 5;
    return DesignConst;
}());
__reflect(DesignConst.prototype, "DesignConst");
//class一个游戏常量的类
var GameConst = (function () {
    function GameConst() {
    }
    GameConst.rewardAdId = "";
    GameConst.bannerAdId = "";
    /** rubbish */
    GameConst.s1 = "adunit-";
    /** 是否使用服务器存储 */
    GameConst.save_server = false;
    GameConst.version = 4;
    GameConst.localversion = "localversion";
    return GameConst;
}());
__reflect(GameConst.prototype, "GameConst");
/**刀静止和移动状态*/
var KNIFESTATE;
(function (KNIFESTATE) {
    /**刀静止*/
    KNIFESTATE[KNIFESTATE["NORMAL"] = 0] = "NORMAL";
    /**刀移动*/
    KNIFESTATE[KNIFESTATE["FLYING"] = 1] = "FLYING";
    /**刀子弹*/
    KNIFESTATE[KNIFESTATE["BULLET"] = 2] = "BULLET";
})(KNIFESTATE || (KNIFESTATE = {}));
/**玩家的生存和死亡*/
var GAMESTATE;
(function (GAMESTATE) {
    GAMESTATE[GAMESTATE["START"] = 1] = "START";
    GAMESTATE[GAMESTATE["OVER"] = 2] = "OVER";
})(GAMESTATE || (GAMESTATE = {}));
/**玩家控制状态*/
var PLAYERSTATE;
(function (PLAYERSTATE) {
    /**飞刀初始化等待*/
    PLAYERSTATE[PLAYERSTATE["WAIT"] = 1] = "WAIT";
    /**移动*/
    PLAYERSTATE[PLAYERSTATE["MOVE"] = 2] = "MOVE";
    /**防御*/
    PLAYERSTATE[PLAYERSTATE["DEFENCE"] = 3] = "DEFENCE";
    /**死亡*/
    PLAYERSTATE[PLAYERSTATE["DEAD"] = 4] = "DEAD";
    /**攻击 */
    PLAYERSTATE[PLAYERSTATE["ATK"] = 5] = "ATK";
    /**巡航 */
    PLAYERSTATE[PLAYERSTATE["CRUISE"] = 6] = "CRUISE";
})(PLAYERSTATE || (PLAYERSTATE = {}));
/**皮肤状态*/
var SKINSTATE;
(function (SKINSTATE) {
    /**已激活*/
    SKINSTATE[SKINSTATE["UNLOCK"] = 0] = "UNLOCK";
    /**未激活*/
    SKINSTATE[SKINSTATE["LOCK"] = 1] = "LOCK";
})(SKINSTATE || (SKINSTATE = {}));
var BEGINSTATE;
(function (BEGINSTATE) {
    /**正常*/
    BEGINSTATE[BEGINSTATE["NORMAL"] = 0] = "NORMAL";
    /**未解锁*/
    BEGINSTATE[BEGINSTATE["LOCK"] = 1] = "LOCK";
    /**看视频试玩*/
    BEGINSTATE[BEGINSTATE["TRYPLAY"] = 2] = "TRYPLAY";
    /**分享增加*/
    BEGINSTATE[BEGINSTATE["SHAREADD"] = 3] = "SHAREADD";
    /**看视频增加*/
    BEGINSTATE[BEGINSTATE["WATCHADD"] = 4] = "WATCHADD";
})(BEGINSTATE || (BEGINSTATE = {}));
var SHARETYPE;
(function (SHARETYPE) {
    SHARETYPE[SHARETYPE["SHARE"] = 0] = "SHARE";
    SHARETYPE[SHARETYPE["SHOWOFF"] = 1] = "SHOWOFF";
})(SHARETYPE || (SHARETYPE = {}));
var WATCHTYPE;
(function (WATCHTYPE) {
    WATCHTYPE[WATCHTYPE["ADDKNIFE"] = 0] = "ADDKNIFE";
    WATCHTYPE[WATCHTYPE["TRYPLAY"] = 1] = "TRYPLAY";
})(WATCHTYPE || (WATCHTYPE = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textAlign = "center";
        this.x = (GameData.stageWidth - this.width) / 2;
        this.y = (GameData.stageHeight - this.height) / 2;
    };
    LoadingUI.prototype.onProgress = function (current, total) {
        this.textField.text = "Loading..." + current + "/" + total;
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI", ["RES.PromiseTaskReporter"]);
/**
 *
 * @author
 * 发送HTTP请求 HttpCommand.getInstance().dispatchEvent(HttpEvent.XXXX)
 *
 */
var HttpCommand = (function (_super) {
    __extends(HttpCommand, _super);
    function HttpCommand() {
        return _super.call(this) || this;
    }
    HttpCommand.getInstance = function () {
        if (this.instance == null) {
            this.instance = new HttpCommand();
        }
        return this.instance;
    };
    /** 登录
     * @param code 登录code
     */
    HttpCommand.prototype.getToken = function (code) {
        var url = "GetWXOpenId.ashx";
        var data = { RequestCode: code };
        this.sendRequest(HttpEvent.getToken, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.postUser = function (user) {
        var url = "SaveUserData.ashx";
        var data = user;
        this.sendRequest(HttpEvent.postUser, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.getUser = function (OpenId) {
        var url = "GetUserData.ashx";
        var data = { OpenId: OpenId };
        this.sendRequest(HttpEvent.getUser, url, data, 0);
    };
    /**
     *
     */
    HttpCommand.prototype.sign = function () {
        var url = "UserSign.ashx";
        var data = null;
        this.sendRequest(HttpEvent.getToken, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.saveRank = function (OpenId, ListType, HighScore) {
        var url = "SaveList.ashx";
        var data = { OpenId: OpenId, ListType: ListType, HighScore: HighScore };
        this.sendRequest(HttpEvent.saveRank, url, data, 1);
    };
    /**
     * @param OpenId
     * @param ListType
     * @param SortType aes 升序，des降序
     */
    HttpCommand.prototype.getRank = function (OpenId, ListType, SortType) {
        if (SortType === void 0) { SortType = "aes"; }
        var url = "GetList.ashx";
        var data = { OpenId: OpenId, ListType: ListType, SortType: SortType };
        this.sendRequest(HttpEvent.getRank, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.saveUserData = function (OpenId, FieldName, FieldValue) {
        var url = "SaveUserEnternal.ashx";
        var data = { OpenId: OpenId, FieldName: FieldName, FieldValue: FieldValue };
        this.sendRequest(HttpEvent.saveUserData, url, data, 1);
    };
    /**
     * @param KeyName”:”1001”,
     * @param KeyValue”:”{….}”   json数组
      *@param KeyType”:”Array”,
     */
    HttpCommand.prototype.saveList = function (KeyName, KeyValue, KeyType) {
        if (KeyType === void 0) { KeyType = "Array"; }
        var url = "SaveApplicationValue.ashx";
        var data = { KeyType: KeyType, KeyName: KeyName, KeyValue: KeyValue };
        this.sendRequest(HttpEvent.saveList, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.getList = function (KeyName) {
        var url = "GetApplicationValue.ashx";
        var data = { RequestCode: KeyName };
        this.sendRequest(HttpEvent.getList, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.saveBingAn = function (data) {
        var url = "SaveApplicationCase.ashx";
        this.sendRequest(HttpEvent.saveBingAn, url, data, 1);
    };
    /**
     *
     */
    HttpCommand.prototype.getBingAn = function (Name, Tag) {
        var url = "GetApplicationCase.ashx";
        var data = { Name: Name, Tag: Tag };
        this.sendRequest(HttpEvent.getBingAn, url, data, 1);
    };
    /** 通用接口
     * 所有header有2个
     * @param interf    接口编号
     * @param url       链接
     * @param data      数据
     * @param method    0get 1post
     */
    HttpCommand.prototype.sendRequest = function (interf, url, data, method) {
        if (data === void 0) { data = null; }
        if (method === void 0) { method = 0; }
        url = HttpEvent.httpApi + url;
        var header = { type: "Content-Type", value: "application/json;charset=UTF-8" };
        var header1 = { type: "AppId", value: HttpEvent.appid };
        HttpManager.getInstance().sendRequest(interf, url, [header, header1], data, method == 0 ? egret.HttpMethod.GET : egret.HttpMethod.POST);
    };
    return HttpCommand;
}(egret.EventDispatcher));
__reflect(HttpCommand.prototype, "HttpCommand");
var HttpEvent = (function (_super) {
    __extends(HttpEvent, _super);
    function HttpEvent(type, bubbles, cancelable) {
        if (bubbles === void 0) { bubbles = false; }
        if (cancelable === void 0) { cancelable = false; }
        var _this = _super.call(this, type, bubbles, cancelable) || this;
        _this.data = null;
        return _this;
    }
    /** rubbish */
    HttpEvent.s1 = "25ac";
    HttpEvent.s2 = "21baadc6fbd";
    /**与服务端通信地址 */
    HttpEvent.httpApi = "https://www.remvd.com/WXGAPI/";
    /**游戏的appid */
    HttpEvent.appid = "wxe608ae48fcc1cb6c";
    /** api接口版本 */
    HttpEvent.version = "1.0";
    /** ---------------------------- 接口协议 --------------------------------------- */
    /** 获取Token */
    HttpEvent.getToken = "getToken";
    /**  */
    HttpEvent.postUser = "postUser";
    /**  */
    HttpEvent.getUser = "getUser";
    /**  */
    HttpEvent.sign = "sign";
    /**  */
    HttpEvent.saveRank = "saveRank";
    /**  */
    HttpEvent.getRank = "getRank";
    /**  */
    HttpEvent.saveUserData = "saveUserData";
    /**  */
    HttpEvent.saveList = "saveList";
    /**  */
    HttpEvent.getList = "getList";
    /**  */
    HttpEvent.saveBingAn = "saveBingAn";
    /**  */
    HttpEvent.getBingAn = "getBingAn";
    return HttpEvent;
}(egret.Event));
__reflect(HttpEvent.prototype, "HttpEvent");
var HttpManager = (function (_super) {
    __extends(HttpManager, _super);
    function HttpManager() {
        return _super.call(this) || this;
    }
    HttpManager.getInstance = function () {
        if (this.instance == null) {
            this.instance = new HttpManager();
        }
        return this.instance;
    };
    /**发送http请求
     * @param interf 接口编号
     * @param url   接口链接
     * @param headers 协议头
     * @param data 携带参数
     * @param method 请求类型 仅支持egret.HttpMethod.GET / egret.HttpMethod.POST
     */
    HttpManager.prototype.sendRequest = function (interf, url, headers, data, method) {
        if (data === void 0) { data = null; }
        if (method === void 0) { method = "GET"; }
        console.log("发送消息:", interf, url, data);
        var request = new egret.HttpRequest();
        request.responseType = egret.HttpResponseType.TEXT;
        request.open(url, method);
        for (var i = 0; i < headers.length; i++) {
            var o = headers[i];
            request.setRequestHeader(o['type'], o['value']);
        }
        request.once(egret.IOErrorEvent.IO_ERROR, function (e) {
            console.log("IOERROR:", interf, e.currentTarget);
            var event = new HttpEvent(interf);
            event.data = "ioerror";
            HttpCommand.getInstance().dispatchEvent(event);
        }, this);
        request.once(egret.ProgressEvent.PROGRESS, function (e) { }, this);
        request.once(egret.Event.COMPLETE, function (e) {
            var response = JSON.parse(e.currentTarget.response);
            var code = response['code'];
            if (code != 0) {
                console.log("请求--" + interf + "--失败:", response);
                var event_1 = new HttpEvent(interf);
                event_1.data = "fail";
                HttpCommand.getInstance().dispatchEvent(event_1);
            }
            else {
                console.log("收到消息:", interf, response);
                var event_2 = new HttpEvent(interf);
                event_2.data = response.data;
                HttpCommand.getInstance().dispatchEvent(event_2);
            }
        }, this);
        request.send(data);
    };
    return HttpManager;
}(egret.EventDispatcher));
__reflect(HttpManager.prototype, "HttpManager");
var BeginLogic = (function () {
    function BeginLogic() {
        this.max = 5;
        this.crt = 1;
        this.addknife = 0;
    }
    /**构建BeginLogic的单例 */
    BeginLogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new BeginLogic();
        }
        return this.instance;
    };
    BeginLogic.prototype.openUI = function (con, _ui, arg) {
        if (arg === void 0) { arg = null; }
        if (this.ui == null) {
            this.ui = _ui;
            con.addChild(this.ui);
            this.ui.logic = this;
            if (this.ui.inited) {
                this.init();
            }
        }
    };
    BeginLogic.prototype.init = function () {
        console.log("BeginLogic.init", this.ui.inited, this.ui.logic);
        this.checkFit();
        this.initData();
        this.initView();
        this.initEvent();
    };
    BeginLogic.prototype.checkFit = function () {
        this.ui.gp_bg.height = this.ui.rect_bg.height = this.ui.img_bg.height = GameData.stageHeight;
    };
    BeginLogic.prototype.initData = function () {
        this.ui.lbl_cast_title.text = "2019.2.23更新公告";
        this.ui.lbl_cast.text = "1.优化防御状态；\n" +
            "2.修复飞刀被击飞后的所有都有震动效果的bug\n" +
            //"\n" +
            //"\n" +
            //"\n" +
            "下次更新预告：\n" +
            "1.增加皮肤\n" +
            "2.增加击杀效果\n" +
            "";
    };
    BeginLogic.prototype.initView = function () {
        this.bmp_bg = Maplogic.getInstance().getMapBg(GameData.stageWidth, GameData.stageHeight);
        //this.bmp_bg = Maplogic.getInstance().getMapBg(20, GameData.stageHeight);
        this.ui.gp_bg.addChild(this.bmp_bg);
        this.cast_bg = Maplogic.getInstance().getMapBg(640, 780);
        this.cast_bg.x = 55;
        this.cast_bg.y = 287;
        this.ui.gp_cast.addChildAt(this.cast_bg, 1);
        this.crtVO = Maplogic.getInstance().getBeginPlayerVO();
        this.beginplayer = new BeginPlayer(this.crtVO);
        if (this.checkVersion()) {
            this.beginplayer.updateCenter(BEGINSTATE.NORMAL);
            this.ui.img_logo.visible = false;
        }
        else {
            // this.ui.img_logo.visible = true;
            this.beginplayer.updateCenter(BEGINSTATE.SHAREADD);
        }
        this.beginplayer.x = this.ui.width / 2;
        this.beginplayer.y = this.ui.img_left.y + this.ui.img_left.height / 2;
        this.ui.addChildAt(this.beginplayer, 2);
        this.ui.gp_cast.visible = this.checkCast();
        platform.bannershow(GameConst.bannerAdId, GameData.stageHeight);
        platform.createGameClubButton(12.5, this.ui.lbl_quan.y - 52, GameData.stageWidth, GameData.stageHeight);
    };
    BeginLogic.prototype.checkVersion = function () {
        var time = new Date().getTime();
        console.log(time);
        var vtime = 1551083540959 + 1000 * 3600 * 24;
        return time < vtime;
    };
    BeginLogic.prototype.checkCast = function () {
        var localversion = WxApi.getInstance().getLocalData(GameConst.localversion);
        var v = parseInt(localversion);
        if (localversion == null || localversion == "") {
            v = 0;
        }
        WxApi.getInstance().setLocalDataByString(GameConst.localversion, GameConst.version + "");
        return v < GameConst.version;
    };
    BeginLogic.prototype.initEvent = function () {
        this.ui.lbl_start.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickStart, this);
        this.ui.img_closecast.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closeCast, this);
        this.ui.img_bg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closeCast, this);
        this.ui.lbl_share.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickShare, this);
        this.ui.lbl_add.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickAdd, this);
        this.ui.img_left.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickLeft, this);
        this.ui.img_right.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickRight, this);
        this.beginplayer.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickBeginPlayer, this);
        WxApi.getInstance().addEventListener(GameEvent.REWARDAD_CLOSE_EVENT, this.watchReward, this);
        GameData.GameStage.addEventListener(egret.Event.ENTER_FRAME, this.enterframe, this);
    };
    BeginLogic.prototype.clickBeginPlayer = function () {
        var _this = this;
        if (this.beginplayer != null && this.beginplayer.vo != null) {
            switch (this.beginplayer.beginstate) {
                case BEGINSTATE.LOCK:
                case BEGINSTATE.NORMAL:
                    return;
                case BEGINSTATE.SHAREADD:
                    WxApi.getInstance().share(SHARETYPE.SHARE);
                    egret.lifecycle.onPause = function () {
                        _this.pause();
                    };
                    egret.lifecycle.onResume = function () {
                        _this.resume();
                    };
                    break;
                case BEGINSTATE.TRYPLAY:
                    WxApi.getInstance().showRewardAd(WATCHTYPE.TRYPLAY);
                    break;
                case BEGINSTATE.WATCHADD:
                    WxApi.getInstance().showRewardAd(WATCHTYPE.ADDKNIFE);
                    break;
            }
        }
    };
    BeginLogic.prototype.clickLeft = function () {
        if (this.crt <= 1) {
            return;
        }
        this.crt--;
        this.ui.img_left.visible = this.crt > 1;
        this.ui.img_right.visible = this.crt < this.max;
        this.initSkin();
    };
    BeginLogic.prototype.clickRight = function () {
        if (this.crt >= this.max) {
            return;
        }
        this.crt++;
        this.ui.img_left.visible = this.crt > 1;
        this.ui.img_right.visible = this.crt < this.max;
        this.initSkin();
    };
    BeginLogic.prototype.initSkin = function () {
        var vo = SkinLogic.getInstance().getSkinVOByID(this.crt);
        if (vo != null) {
            this.crtVO.skinvo = vo;
            this.beginplayer.updateCenter(BEGINSTATE.SHAREADD);
            this.beginplayer.updateVO(this.crtVO);
        }
    };
    BeginLogic.prototype.clickAdd = function () {
        WxApi.getInstance().showRewardAd(WATCHTYPE.ADDKNIFE);
    };
    BeginLogic.prototype.watchReward = function (e) {
        if (e.data.data == 0) {
            if (e.data.type == WATCHTYPE.ADDKNIFE) {
                this.addknife = 5;
                WxApi.getInstance().toast("飞刀+3");
                this.beginplayer.updateCenter(BEGINSTATE.NORMAL);
            }
            else if (e.data.type == WATCHTYPE.TRYPLAY) {
                this.beginplayer.updateCenter(BEGINSTATE.SHAREADD);
                this.clickStart();
            }
        }
    };
    BeginLogic.prototype.closeCast = function () {
        this.ui.gp_cast.visible = false;
    };
    BeginLogic.prototype.enterframe = function () {
        if (this.beginplayer != null) {
            this.beginplayer.update();
        }
    };
    BeginLogic.prototype.clearEvent = function () {
        this.ui.lbl_start.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickStart, this);
        this.ui.img_closecast.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closeCast, this);
        this.ui.img_bg.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closeCast, this);
        this.ui.lbl_share.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickShare, this);
        this.ui.lbl_add.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickAdd, this);
        this.ui.img_left.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickLeft, this);
        this.ui.img_right.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickRight, this);
        this.beginplayer.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickBeginPlayer, this);
        WxApi.getInstance().removeEventListener(GameEvent.REWARDAD_CLOSE_EVENT, this.watchReward, this);
        GameData.GameStage.removeEventListener(egret.Event.ENTER_FRAME, this.enterframe, this);
    };
    BeginLogic.prototype.clickShare = function () {
        WxApi.getInstance().share(SHARETYPE.SHARE);
    };
    BeginLogic.prototype.pause = function () {
        var _this = this;
        console.log("beinglogic:pause");
        this.shareId = egret.setTimeout(function () {
            _this.addknife = 2;
            if (_this.beginplayer != null) {
                _this.beginplayer.updateCenter(BEGINSTATE.WATCHADD);
            }
        }, this, 2500);
    };
    BeginLogic.prototype.resume = function () {
        console.log("beginloic:resume");
        egret.clearTimeout(this.shareId);
    };
    BeginLogic.prototype.clickStart = function () {
        if (this.beginplayer.state == BEGINSTATE.TRYPLAY || this.beginplayer.state == BEGINSTATE.LOCK) {
            return;
        }
        var obj = {
            bgId: this.crtVO.bg_id,
            skinId: this.crtVO.skinvo.id,
            num: this.crtVO.knife_num + this.addknife
        };
        GameLogic.getInstance().openUI(GameData.main, new GameUI(), obj);
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
    };
    BeginLogic.prototype.clear = function () {
        this.clearEvent();
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
        this.ui = null;
        this.addknife = 0;
        this.beginplayer.clear();
        this.crtVO.clear();
        this.crtVO = null;
        this.beginplayer = null;
    };
    return BeginLogic;
}());
__reflect(BeginLogic.prototype, "BeginLogic");
var GameLogic = (function () {
    function GameLogic() {
    }
    GameLogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new GameLogic();
        }
        return this.instance;
    };
    GameLogic.prototype.openUI = function (con, _ui, arg) {
        if (arg === void 0) { arg = null; }
        if (this.ui == null) {
            this.ui = _ui;
            this.args = arg;
            con.addChild(this.ui);
            this.ui.logic = this;
            if (this.ui.inited) {
                this.init();
            }
        }
    };
    GameLogic.prototype.init = function () {
        console.log("GameLogic.init", this.ui.inited, this.ui.logic);
        this.checkFit();
        this.initData();
        this.initView();
        this.initEvent();
    };
    GameLogic.prototype.checkFit = function () {
    };
    GameLogic.prototype.initData = function () {
    };
    GameLogic.prototype.initView = function () {
        Maplogic.getInstance().openUI(this.ui, new MapCon(), this.args);
        RockerLogic.getInstance().openUI(this.ui, new Rocker());
        RightRockerLogic.getInstance().openUI(this.ui, new Rocker());
        this.initRank();
        this.startGame();
    };
    /**初始的排名 */
    GameLogic.prototype.initRank = function () {
        for (var i = 1; i <= 5; i++) {
            this.ui['lbl_rank' + i + '_name'].text = "";
            this.ui['lbl_rank' + i + '_num'].text = "";
            this.ui['lbl_rank' + i + '_src'].texture = null;
        }
    };
    /**攻击按钮是否显示 */
    GameLogic.prototype.aupdate = function () {
        if (RockerLogic.getInstance().isatk == false) {
            this.ui.atk.visible = false;
            RolePlayer.getInstance().updateATKDirection(false);
        }
        else {
            this.ui.atk.visible = true;
            RolePlayer.getInstance().updateATKDirection(true);
        }
    };
    /**计算第几名的方法 */
    GameLogic.prototype.updateRank = function (arr) {
        this.myrank = 1;
        for (var i = 1; i <= 5; i++) {
            var player = arr[i - 1];
            if (player != null) {
                if (player.vo.id == 0) {
                    this.myrank = i;
                }
                this.ui['lbl_rank' + i + '_name'].text = player.vo.name;
                this.ui['lbl_rank' + i + '_num'].text = player.vo.knife_num + "";
                this.ui['lbl_rank' + i + '_src'].texture = RES.getRes("yuan_" + player.vo.bg_id);
            }
            else {
                this.ui['lbl_rank' + i + '_name'].text = "";
                this.ui['lbl_rank' + i + '_num'].text = "";
                this.ui['lbl_rank' + i + '_src'].texture = null;
            }
        }
        if (this.myrank == 1 && arr.length == 1) {
            this.gameover();
        }
    };
    GameLogic.prototype.startGame = function () {
        platform.bannershow(GameConst.bannerAdId, GameData.stageHeight);
        this.ui.gp_over.x = -this.ui.gp_over.width;
        /**显示隐藏第几名的界面 */
        this.ui.gp_over.visible = false;
        this.gamestate = GAMESTATE.START;
        //启动摇杆
        RockerLogic.getInstance().start();
        RightRockerLogic.getInstance().start();
        Maplogic.getInstance().start();
        this.lefttime = DesignConst.gametime;
        /**函数每隔多少秒循环执行一次 */
        this.game_countId = egret.setInterval(this.countDown, this, 1000);
    };
    /**游戏倒计时方法 */
    GameLogic.prototype.countDown = function () {
        this.lefttime--;
        this.ui.lbl_count.text = TimeUtil.ParseTime2Format(this.lefttime, "m:s");
        if (this.lefttime <= 0) {
            this.gameover();
        }
    };
    /**玩家死亡或胜利调用 */
    GameLogic.prototype.gameover = function () {
        this.ui.lbl_rank.text = "第" + this.myrank + "名";
        this.ui.gp_over.visible = true;
        egret.Tween.get(this.ui.gp_over).to({ x: 0 }, 600);
        this.gamestate = GAMESTATE.OVER;
        egret.clearInterval(this.game_countId);
        this.openHit();
        RockerLogic.getInstance().clear();
        RightRockerLogic.getInstance().clear();
        Maplogic.getInstance().stop();
    };
    /**死亡或者胜利之后出现名次的界面 */
    GameLogic.prototype.initEvent = function () {
        GameData.GameStage.addEventListener(egret.Event.ENTER_FRAME, this.enterframe, this);
        /**点击炫耀后触发的事件 */
        this.ui.lbl_showoff.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickShowoff, this);
        /**点击首页后触发的事件 */
        this.ui.lbl_back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickBack, this);
    };
    GameLogic.prototype.clearEvent = function () {
        GameData.GameStage.removeEventListener(egret.Event.ENTER_FRAME, this.enterframe, this);
        this.ui.lbl_showoff.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickShowoff, this);
        this.ui.lbl_back.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.clickBack, this);
    };
    GameLogic.prototype.clickShowoff = function () {
        WxApi.getInstance().share(SHARETYPE.SHOWOFF);
    };
    GameLogic.prototype.clickBack = function () {
        BeginLogic.getInstance().openUI(GameData.main, new BeginUI());
        this.clear();
    };
    GameLogic.prototype.enterframe = function () {
        if (this.gamestate == GAMESTATE.START) {
            Maplogic.getInstance().enterframe();
        }
    };
    GameLogic.prototype.clickStart = function () {
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
    };
    GameLogic.prototype.clear = function () {
        Maplogic.getInstance().clear();
        RockerLogic.getInstance().clear();
        RightRockerLogic.getInstance().clear();
        this.clearEvent();
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
        this.ui = null;
    };
    /** 恢复碰撞 */
    GameLogic.prototype.openHit = function () {
        GameData.GameStage.$hitTest = egret.DisplayObjectContainer.prototype.$hitTest;
    };
    return GameLogic;
}());
__reflect(GameLogic.prototype, "GameLogic");
var Maplogic = (function () {
    function Maplogic() {
        this.players = {};
        this.knifes = {};
        this.scale = 1;
        this.canchange = true;
        this.srcinjured = 0; //身上刀的碰撞次数
        this.tarinjured = 0; //身上刀的碰撞次数
    }
    Maplogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new Maplogic();
        }
        return this.instance;
    };
    Maplogic.prototype.openUI = function (con, _ui, arg) {
        if (arg === void 0) { arg = null; }
        if (this.ui == null) {
            this.ui = _ui;
            this.args = arg;
            con.addChildAt(this.ui, 0);
            this.ui.logic = this;
            this.init();
        }
    };
    Maplogic.prototype.init = function () {
        this.initBg();
        this.initKnifes();
        this.initPlayers();
        this.updateMapCrood();
        this.Right();
    };
    Maplogic.prototype.initBg = function () {
        this.bgs = [];
        for (var i = 0; i < 3; i++) {
            for (var j = 0; j < 3; j++) {
                var bg = Maplogic.getInstance().getMapBg(DesignConst.mapwidth / 3, DesignConst.mapheight / 3);
                bg.x = j * DesignConst.mapwidth / 3;
                bg.y = i * DesignConst.mapheight / 3;
                this.ui.addChild(bg);
            }
        }
    };
    /** ------------------------------- players ------------------------- */
    Maplogic.prototype.initPlayers = function () {
        //ai球
        for (var i = 0; i < DesignConst.ai_num; i++) {
            this.addPlayer(i + 1);
        }
        //玩家球
        var myvo = this.getRolePlayerVO();
        this.role = new RolePlayer(myvo);
        this.players[myvo.id] = this.role;
        this.ui.addChild(this.role);
        RockerLogic.getInstance().setControlPlayer(this.role);
    };
    Maplogic.prototype.Right = function () {
        RightRockerLogic.getInstance().setControlPlayer(this.role);
    };
    Maplogic.prototype.addPlayer = function (id) {
        var vo = this.getAIPlayerVO(id);
        var ai = ObjectPool.getObject("AIPlayer");
        ai.updateVO(vo);
        this.ui.addChild(ai);
        this.players[vo.id] = ai;
    };
    Maplogic.prototype.removePlayer = function (id) {
        if (id == 0) {
            GameLogic.getInstance().gameover();
            return;
        }
        var player = this.players[id];
        if (player != null) {
            player.clear();
            if (player.parent != null) {
                player.parent.removeChild(player);
            }
            delete this.players[id];
        }
    };
    Maplogic.prototype.clearPlayers = function () {
        for (var id in this.players) {
            this.removePlayer(id);
        }
    };
    /** ------------------------------ knifes ----------------- */
    /** 检测吃球 */
    Maplogic.prototype.dealEatKnifes = function (x, y, r) {
        var p1 = new egret.Point(x, y);
        var n = 0;
        for (var id in this.knifes) {
            var knife = this.knifes[id];
            //判断刀是否为空，及其状态是否正常
            if (knife != null && knife.state == KNIFESTATE.NORMAL) {
                var p2 = new egret.Point(knife.x, knife.y);
                var dis = egret.Point.distance(p1, p2);
                if (dis <= r && n <= 5) {
                    n++;
                    //删除地面上已被捡起的飞刀，包括敌方捡起的
                    this.removeKnife(id);
                }
            }
        }
        return n;
    };
    //初始化刀
    Maplogic.prototype.initKnifes = function () {
        this.knife_num = 0;
        this.knife_hash = 0;
        for (var i = 0; i < DesignConst.knife_max; i++) {
            this.addKnife(this.knife_hash);
        }
    };
    Maplogic.prototype.checkKnifes = function () {
        if (this.knife_num < DesignConst.knife_max) {
            this.addKnife(this.knife_hash);
        }
    };
    Maplogic.prototype.flyToMap = function (id, srcx, srcy) {
        if (this.ui == null) {
            return;
        }
        //声明计时器
        var knife = ObjectPool.getObject("KnifePlayer");
        knife.init(id, false);
        this.ui.addChild(knife);
        this.knifes[knife.id] = knife;
        this.knife_num++;
        this.knife_hash++;
        knife.x = srcx;
        knife.y = srcy;
        var x = srcx + Math.random() * 1200 - 600;
        var y = srcy + Math.random() * 1200 - 600;
        var p = this.checkBound(x, y, 30);
        /**掉落旋转tween动画 */
        egret.Tween.get(knife, { loop: true }).to({ rotation: 360 }, 300);
        /**飞刀掉落之后旋转停止 */
        egret.Tween.get(knife).to({ x: p.x, y: p.y }, 1200).call(function () {
            //knife.state = KNIFESTATE.NORMAL;
            egret.Tween.removeTweens(knife);
            if (knife.parent) {
                knife.parent.removeChild(knife);
            }
        }, this);
    };
    /**子弹移动距离限制 */
    Maplogic.prototype.checkBound = function (x, y, dis) {
        if (x < dis) {
            x = dis;
        }
        else if (x > DesignConst.mapwidth - dis) {
            x = DesignConst.mapwidth - dis;
        }
        if (y < dis) {
            y = dis;
        }
        else if (y > DesignConst.mapheight - dis) {
            y = DesignConst.mapheight - dis;
        }
        return new egret.Point(x, y);
    };
    Maplogic.prototype.addKnife = function (id) {
        if (this.ui == null) {
            return;
        }
        var knife = ObjectPool.getObject("KnifePlayer");
        knife.init(id);
        //把刀设为此脚本UI的子物体
        this.ui.addChild(knife);
        this.knifes[knife.id] = knife;
        this.knife_num++;
        this.knife_hash++;
    };
    /**删除飞刀 */
    Maplogic.prototype.removeKnife = function (id) {
        var knife = this.knifes[id];
        if (knife != null) {
            knife.clear();
            if (knife.parent != null) {
                knife.parent.removeChild(knife);
            }
            delete this.knifes[id];
            this.knife_num--;
        }
    };
    Maplogic.prototype.clearKnifes = function () {
        for (var id in this.knifes) {
            this.removeKnife(id);
        }
        this.knife_num = 0;
        this.knife_hash = 0;
    };
    /** ----------------------------------------------------------------------- */
    Maplogic.prototype.start = function () {
        var _this = this;
        this.enter_count = 0;
        egret.setTimeout(function () {
            for (var id in _this.players) {
                var p = _this.players[id];
                if (p.vo.id != 0) {
                    //	p.state = PLAYERSTATE.CRUISE;
                }
            }
        }, this, 1000);
    };
    Maplogic.prototype.stop = function () {
        for (var id in this.players) {
            var p = this.players[id];
            p.clear();
        }
    };
    /**初始化状态 */
    Maplogic.prototype.getBeginPlayerVO = function () {
        var vo = ObjectPool.getObject("PlayerVO");
        vo.bg_id = "1";
        vo.knife_num = 5;
        vo.circleRadius = 48;
        vo.turn_speed = 4;
        vo.dis_from_circle = -16;
        vo.name = "玩家";
        vo.skinvo = SkinLogic.getInstance().getSkinVOByID(3);
        return vo;
    };
    Maplogic.prototype.getRolePlayerVO = function () {
        var vo = ObjectPool.getObject("PlayerVO");
        vo.id = 0;
        vo.bg_id = this.args.bgId;
        vo.knife_num = this.args.num;
        vo.skinvo = SkinLogic.getInstance().getSkinVOByID(this.args.skinId);
        vo.circleRadius = 32;
        vo.turn_speed = DesignConst.role_turn_speed;
        vo.move_speed = DesignConst.role_move_speed;
        vo.name = WxApi.getInstance().userInfo.nickname;
        return vo;
    };
    /**右上角电脑的显示 */
    Maplogic.prototype.getAIPlayerVO = function (id) {
        var vo = ObjectPool.getObject("PlayerVO");
        vo.id = id;
        vo.bg_id = GameUtil.between(1, 5) + "";
        vo.knife_num = 5;
        vo.skinvo = SkinLogic.getInstance().getSkinVOByID(GameUtil.between(1, 5));
        vo.circleRadius = 32;
        vo.turn_speed = DesignConst.ai_turn_speed;
        vo.move_speed = DesignConst.ai_move_speed;
        vo.name = "电脑" + vo.id;
        return vo;
    };
    /**玩家球位置改变时 地图跟着改变 */
    Maplogic.prototype.updateMapCrood = function () {
        if (this.ui == null) {
            return;
        }
        this.ui.scaleX = this.ui.scaleY = this.scale;
        var tarx = -(this.role.x) * this.scale + GameData.stageWidth / 2;
        var tary = -(this.role.y) * this.scale + GameData.stageHeight / 2;
        this.ui.x = tarx;
        this.ui.y = tary;
    };
    Maplogic.prototype.enterframe = function () {
        this.updatePlayerBalls();
        if (this.enter_count % DesignConst.knife_frest_rate == 0) {
            this.checkKnifes();
        }
        this.enter_count++;
    };
    Maplogic.prototype.sortPlayers = function (a, b) {
        if (a.vo.knife_num > b.vo.knife_num) {
            return -1;
        }
        else {
            return 1;
        }
    };
    /**更新玩家球状态 */
    Maplogic.prototype.updatePlayerBalls = function () {
        var arr = [];
        for (var id in this.players) {
            var player = this.players[id];
            arr.push(player);
        }
        //排序 并刷新排行榜
        arr.sort(this.sortPlayers);
        GameLogic.getInstance().updateRank(arr);
        this.updatePlayerBallsState(arr);
        //调动攻击按钮
        GameLogic.getInstance().aupdate();
    };
    /**更新玩家状态  坐标-->吞噬-->逃逸-->追击-->block */
    Maplogic.prototype.updatePlayerBallsState = function (arr) {
        while (arr.length > 0) {
            var p = arr.shift();
            p.update();
            this.setPlayerBallsState(p, arr); //如果返回return则代表玩家死亡
        }
    };
    Maplogic.prototype.setPlayerBallsState = function (srcplayer, tarplayers) {
        var eated = false;
        for (var i = 0; i < tarplayers.length; i++) {
            var tarplayer = tarplayers[i];
            eated = this.dealHit(srcplayer, tarplayer); //如果返回一个值，fals，代表玩家死亡
            //srcplayer被吃掉了 return
            if (eated) {
                return;
            }
        }
    };
    Maplogic.prototype.dealHit = function (srcplayer, tarplayer) {
        var dis = srcplayer.vo.radius + tarplayer.vo.radius;
        if (srcplayer.state == PLAYERSTATE.DEFENCE || tarplayer.state == PLAYERSTATE.DEFENCE) {
            dis += 30;
        }
        var p1 = new egret.Point(srcplayer.x, srcplayer.y);
        var p2 = new egret.Point(tarplayer.x, tarplayer.y);
        //如果两个玩家之间距离小于其半径范围
        var b1 = egret.Point.distance(p1, p2) < dis;
        if (b1 = true) {
            var src_kill = void 0;
            var tar_kill = void 0;
            var p3 = void 0;
            /**knife在地图中的坐标*/
            var p4 = void 0;
            var p5 = void 0;
            /**tarknife在地图中的坐标 */
            var p6 = void 0;
            var p7 = void 0;
            for (var i = 0; i < srcplayer.knifes.length; i++) {
                var knife = srcplayer.knifes[i];
                if (srcplayer.state == PLAYERSTATE.DEFENCE) {
                    p3 = knife.localToGlobal(knife.width / 2, knife.height);
                }
                else {
                    p3 = knife.localToGlobal(knife.width / 2, knife.height / 2);
                }
                p4 = this.ui.globalToLocal(p3.x, p3.y); //knife在地图中的坐标
                //先检测tar圆心，优先击杀			
                var d2 = egret.Point.distance(p4, p2);
                if (d2 < tarplayer.vo.circleRadius) {
                    if (tarplayer.vo.id == 0) {
                        platform.vibrate(true);
                    }
                    egret.Tween.removeTweens(knife); //删除刀身上tween动画
                    srcplayer.removeKnife(i);
                    this.removePlayer(tarplayer.vo.id);
                    return;
                }
                //遍历飞刀
                for (var j = 0; j < tarplayer.knifes.length; j++) {
                    var tarknife = tarplayer.knifes[j];
                    if (tarplayer.state == PLAYERSTATE.DEFENCE) {
                        p5 = tarknife.localToGlobal(tarknife.width / 2, tarknife.height);
                    }
                    else {
                        p5 = tarknife.localToGlobal(tarknife.width / 2, tarknife.height / 2);
                    }
                    p6 = this.ui.globalToLocal(p5.x, p5.y); //tarknife在地图中的坐标
                    //先检测src圆心，优先击杀
                    d2 = egret.Point.distance(p6, p1);
                    if (d2 < srcplayer.vo.circleRadius) {
                        if (srcplayer.vo.id == 0) {
                            platform.vibrate(true);
                        }
                        egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                        tarplayer.removeKnife(j);
                        this.removePlayer(srcplayer.vo.id);
                        return;
                    }
                    //arc飞刀坐标 tar飞刀坐标
                    d2 = egret.Point.distance(p4, p6);
                    var b2 = d2 < tarknife.height / 2;
                    /**是否调动手机震动 */
                    var ss = false;
                    if (b2) {
                        if (srcplayer.state == PLAYERSTATE.DEFENCE && tarplayer.state == PLAYERSTATE.CRUISE) {
                            this.srcinjured++;
                            if (this.srcinjured > 4) {
                                egret.Tween.removeTweens(knife); //删除刀身上tween动画
                                //碰撞后删除飞刀
                                srcplayer.removeKnife(i);
                                if (srcplayer.vo.id == 0) {
                                    ss = true;
                                }
                                this.srcinjured = 0;
                                //飞刀碰撞后生成新的飞刀在地上
                                this.flyToMap(this.knife_hash, p4.x, p4.y);
                            }
                            this.tarinjured++;
                            if (this.tarinjured > 1) {
                                egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                                tarplayer.removeKnife(j);
                                if (tarplayer.vo.id == 0) {
                                    ss = true;
                                }
                                this.flyToMap(this.knife_hash, p6.x, p6.y);
                                if (ss) {
                                    platform.vibrate(true);
                                }
                                this.tarinjured = 0;
                            }
                            return;
                        }
                        if (srcplayer.state == PLAYERSTATE.DEFENCE && tarplayer.state == PLAYERSTATE.ATK) {
                            this.srcinjured++;
                            console.log(this.srcinjured);
                            if (this.srcinjured > 4) {
                                egret.Tween.removeTweens(knife); //删除刀身上tween动画
                                srcplayer.removeKnife(i);
                                if (srcplayer.vo.id == 0) {
                                    ss = true;
                                }
                                this.flyToMap(this.knife_hash, p4.x, p4.y);
                                this.srcinjured = 0;
                            }
                            egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                            tarplayer.removeKnife(j);
                            if (tarplayer.vo.id == 0) {
                                ss = true;
                            }
                            this.flyToMap(this.knife_hash, p6.x, p6.y);
                            if (ss) {
                                platform.vibrate(true);
                            }
                            this.tarinjured = 0;
                            return;
                        }
                        if (srcplayer.state == PLAYERSTATE.CRUISE && tarplayer.state == PLAYERSTATE.ATK) {
                            this.srcinjured++;
                            console.log(this.srcinjured);
                            if (this.srcinjured > 1) {
                                //碰撞后删除飞刀
                                egret.Tween.removeTweens(knife); //删除刀身上tween动画
                                srcplayer.removeKnife(i);
                                if (srcplayer.vo.id == 0) {
                                    ss = true;
                                }
                                //飞刀碰撞后生成新的飞刀在地上
                                this.flyToMap(this.knife_hash, p4.x, p4.y);
                                this.srcinjured = 0;
                            }
                            egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                            tarplayer.removeKnife(j);
                            if (tarplayer.vo.id == 0) {
                                ss = true;
                            }
                            this.flyToMap(this.knife_hash, p6.x, p6.y);
                            if (ss) {
                                platform.vibrate(true);
                            }
                            this.tarinjured = 0;
                            return;
                        }
                        if (srcplayer.state == PLAYERSTATE.ATK && tarplayer.state == PLAYERSTATE.ATK) {
                            egret.Tween.removeTweens(knife); //删除刀身上tween动画
                            srcplayer.removeKnife(i);
                            if (srcplayer.vo.id == 0) {
                                ss = true;
                            }
                            this.flyToMap(this.knife_hash, p4.x, p4.y);
                            this.srcinjured = 0;
                            egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                            tarplayer.removeKnife(j);
                            if (tarplayer.vo.id == 0) {
                                ss = true;
                            }
                            this.flyToMap(this.knife_hash, p6.x, p6.y);
                            if (ss) {
                                platform.vibrate(true);
                            }
                            this.tarinjured = 0;
                            return;
                        }
                        if (srcplayer.state == PLAYERSTATE.CRUISE && tarplayer.state == PLAYERSTATE.CRUISE) {
                            this.srcinjured++;
                            this.tarinjured++;
                            if (this.srcinjured > 1) {
                                egret.Tween.removeTweens(knife); //删除刀身上tween动画
                                //碰撞后删除飞刀
                                srcplayer.removeKnife(i);
                                if (srcplayer.vo.id == 0) {
                                    ss = true;
                                }
                                this.srcinjured = 0;
                                //飞刀碰撞后生成新的飞刀在地上
                                this.flyToMap(this.knife_hash, p4.x, p4.y);
                            }
                            if (this.tarinjured > 1) {
                                egret.Tween.removeTweens(tarknife); //删除刀身上tween动画
                                tarplayer.removeKnife(j);
                                if (tarplayer.vo.id == 0) {
                                    ss = true;
                                }
                                this.flyToMap(this.knife_hash, p6.x, p6.y);
                                if (ss) {
                                    platform.vibrate(true);
                                }
                                this.tarinjured = 0;
                            }
                            return;
                        }
                        if (tarplayer.state == PLAYERSTATE.DEFENCE && srcplayer.state == PLAYERSTATE.DEFENCE) {
                            this.flyToMap(this.knife_hash, p4.x, p4.y);
                            if (srcplayer.vo.id == 0 || tarplayer.vo.id == 0) {
                                ss = true;
                            }
                            if (ss) {
                                platform.vibrate(true);
                            }
                            return;
                        }
                        // if (tarplayer.state == PLAYERSTATE.DEFENCE && srcplayer.state != PLAYERSTATE.DEFENCE) {//tar处于防御状态，src不是
                        // 	if (Math.random() < 0.3) {
                        // 		tarplayer.removeKnife(i);
                        // 		if (tarplayer.vo.id == 0) {
                        // 			ss = true;
                        // 		}
                        // 		this.flyToMap(this.knife_hash, p4.x, p4.y);
                        // 	}
                        // 	if (srcplayer.vo.id == 0) {
                        // 		ss = true;
                        // 	}
                        // 	srcplayer.removeKnife(j);
                        // 	this.flyToMap(this.knife_hash, p6.x, p6.y);
                        // 	if (ss) {
                        // 		platform.vibrate(true);
                        // 	}
                        // 	return;
                        // }
                        // //都不在防御状态
                        // if (srcplayer.knifes.length > tarplayer.knifes.length) {//大的飞刀 有概率不掉飞刀
                        // 	if (Math.random() < 0.8) {
                        // 		srcplayer.removeKnife(i);
                        // 		if (srcplayer.vo.id == 0) {
                        // 			ss = true;
                        // 		}
                        // 		this.flyToMap(this.knife_hash, p4.x, p4.y);
                        // 	}
                        // 	tarplayer.removeKnife(j);
                        // 	if (tarplayer.vo.id == 0) {
                        // 		ss = true;
                        // 	}
                        // 	this.flyToMap(this.knife_hash, p6.x, p6.y);
                        // }
                        // else if (srcplayer.knifes.length < tarplayer.knifes.length) {
                        // 	if (Math.random() < 0.8) {
                        // 		tarplayer.removeKnife(i);
                        // 		if (tarplayer.vo.id == 0) {
                        // 			ss = true;
                        // 		}
                        // 		this.flyToMap(this.knife_hash, p4.x, p4.y);
                        // 	}
                        // 	if (srcplayer.vo.id == 0) {
                        // 		ss = true;
                        // 	}
                        // 	srcplayer.removeKnife(j);
                        // 	this.flyToMap(this.knife_hash, p6.x, p6.y);
                        // }
                        // else {
                        // 	srcplayer.removeKnife(i);
                        // 	this.flyToMap(this.knife_hash, p4.x, p4.y);
                        // 	tarplayer.removeKnife(j);
                        // 	this.flyToMap(this.knife_hash, p6.x, p6.y);
                        // 	if (srcplayer.vo.id == 0 || tarplayer.vo.id == 0) {
                        // 		ss = true;
                        // 	}
                        // }
                        if (ss) {
                            platform.vibrate(true);
                        }
                        return;
                    }
                }
            }
        }
        return false;
    };
    Maplogic.prototype.clear = function () {
        this.clearKnifes();
        this.clearPlayers();
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
        this.ui = null;
    };
    /** ------------------------------------------------------------------------------------ */
    Maplogic.prototype.getMapBg = function (w, h) {
        var unit = 68;
        var w1 = Math.ceil(w / unit);
        var h1 = Math.ceil(h / unit);
        var con = new egret.DisplayObjectContainer();
        for (var i = 0; i < h1; i++) {
            for (var j = 0; j < w1; j++) {
                var r = Math.random();
                var src = r < 0.9 ? 2 : (r < 0.95 ? 1 : 3);
                var bmp = new egret.Bitmap(RES.getRes("game_json.di_" + src));
                bmp.x = j * unit;
                bmp.y = i * unit;
                con.addChild(bmp);
            }
        }
        return GameUtil.drawBitmapFromDisObject(con, new egret.Rectangle(0, 0, w, h), 1);
    };
    return Maplogic;
}());
__reflect(Maplogic.prototype, "Maplogic");
//摇杆逻辑
var RightRockerLogic = (function () {
    function RightRockerLogic() {
        this.ballRadius = 0; //小球半径f
        this.circleRadius = 0; //圆环半径
        this.centerX = 0; //中心点坐标
        this.centerY = 0;
        //触摸移动，设置小球的位置
        this.p1 = new egret.Point();
        this.p2 = new egret.Point();
    }
    RightRockerLogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new RightRockerLogic();
        }
        return this.instance;
    };
    RightRockerLogic.prototype.openUI = function (con, _ui, arg) {
        if (arg === void 0) { arg = null; }
        if (this.ui == null) {
            this.ui = _ui;
            con.addChild(this.ui);
            if (this.ui.inited) {
                this.init();
            }
            this.ui.logic = this;
        }
        /**显示或隐藏摇杆 */
        this.ui.visible = true;
    };
    RightRockerLogic.prototype.init = function () {
        console.log("RockerLogic.init", this.ui.inited, this.ui.logic);
        /**中间球半径 */
        this.ballRadius = this.ui.ball.height / 2;
        /**外面球半径 */
        this.circleRadius = this.ui.circle.height / 2;
        //获取中心点
        this.centerX = this.circleRadius;
        this.centerY = this.circleRadius;
        //设置锚点
        this.ui.anchorOffsetX = this.circleRadius;
        this.ui.anchorOffsetY = this.circleRadius;
        this.ui.ball.anchorOffsetX = this.ballRadius;
        this.ui.ball.anchorOffsetY = this.ballRadius;
        //设置小球初始位置
        this.ui.ball.x = this.centerX;
        this.ui.ball.y = this.centerY;
        this.initCrood();
    };
    RightRockerLogic.prototype.initCrood = function () {
        //摇杆在屏幕初始位置
        this.ui.x = GameData.GameStage.stageWidth / 5 + 660;
        this.ui.y = GameData.GameStage.stageHeight - this.circleRadius - 20;
    };
    /**启动虚拟摇杆 (监听事件根据实际情况设置，不然点一下UI上的其他按钮，也会触发虚拟摇杆事件。)*/
    RightRockerLogic.prototype.start = function () {
        this.started = true;
        GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
        GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
        GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
    };
    /**停止虚拟摇杆*/
    RightRockerLogic.prototype.stop = function () {
        this.started = true;
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
        this.touchID = null;
    };
    /**在哪触摸开始，就在哪显示虚拟摇杆*/
    RightRockerLogic.prototype.onTouchBegin = function (e) {
        var _this = this;
        if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
            return;
        }
        //点击摇杆时 屏蔽所有碰撞
        GameData.GameStage.$hitTest = function (x, y) { return _this.ui; };
        this.touchID = e.touchPointID;
        /**或许是鼠标按下点的坐标
        this.ui.x = e.stageX;
        this.ui.y = e.stageY;
        this.p1.x = this.ui.x;
        this.p1.y = this.ui.y;
        this.ui.ball.x = this.centerX;
        this.ui.ball.y = this.centerY;
        */
    };
    RightRockerLogic.prototype.onTouchMove = function (e) {
        if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
            return;
        }
        //获取手指和虚拟摇杆的距离
        this.p1.x = this.ui.x;
        this.p1.y = this.ui.y;
        this.p2.x = e.stageX;
        this.p2.y = e.stageY;
        //计算两点距离
        var dist = egret.Point.distance(this.p1, this.p2);
        var angle = Math.atan2(e.stageY - this.ui.y, e.stageX - this.ui.x);
        //手指距离在圆环范围内
        if (this.p2.x > 850 && this.p2.y > 500 && this.p2.x < 950) {
            if (dist <= (this.circleRadius - this.ballRadius)) {
                this.ui.ball.x = this.centerX + e.stageX - this.ui.x;
                this.ui.ball.y = this.centerY + e.stageY - this.ui.y;
                //手指距离在圆环范围外
            }
            else {
                this.ui.ball.x = Math.cos(angle) * (this.circleRadius - this.ballRadius) + this.centerX;
                this.ui.ball.y = Math.sin(angle) * (this.circleRadius - this.ballRadius) + this.centerY;
            }
            if (dist >= 3) {
                var p1 = new egret.Point(this.ui.ball.x, this.ui.ball.y);
                var p2 = new egret.Point(this.centerX, this.centerY);
                var dis = egret.Point.distance(p1, p2);
                var rate = dis / (this.circleRadius - this.ballRadius);
                this.moveBall(angle, rate);
            }
            this.changetime = egret.getTimer();
            e.stopImmediatePropagation();
        }
    };
    //触摸结束，隐藏虚拟摇杆
    RightRockerLogic.prototype.onTouchEnd = function (e) {
        if (this.p2.x < 500) {
            RockerLogic.getInstance().ui.visible = false;
        }
        GameLogic.getInstance().openHit();
        this.touchID = null;
        //if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
        //	return;
        //}
        this.p2.x = e.stageX;
        this.p2.y = e.stageY;
        if (this.controlplayer != null) {
            this.controlplayer.updateRightDirection(null);
        }
        this.initCrood();
        //小球恢复初始位置
        this.ui.ball.x = this.centerX;
        this.ui.ball.y = this.centerY;
    };
    /**要控制的球 */
    RightRockerLogic.prototype.setControlPlayer = function (ball) {
        this.controlplayer = ball;
    };
    /**球体移动 */
    RightRockerLogic.prototype.moveBall = function (hu, rate) {
        var p6 = this.ui.globalToLocal(this.centerX, this.centerY);
        var p5 = this.ui.globalToLocal(this.ui.ball.x, this.ui.ball.y);
        if (this.controlplayer != null && p6 != p5) {
            var dir = hu * 180 / Math.PI + 90;
            this.controlplayer.updateRightDirection(dir);
        }
    };
    RightRockerLogic.prototype.clear = function () {
        this.controlplayer = null;
        this.stop();
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
        this.ui = null;
    };
    return RightRockerLogic;
}());
__reflect(RightRockerLogic.prototype, "RightRockerLogic");
//摇杆逻辑
var RockerLogic = (function () {
    function RockerLogic() {
        this.ballRadius = 0; //小球半径
        this.circleRadius = 0; //圆环半径
        this.centerX = 0; //中心点坐标
        this.centerY = 0;
        this.p3 = new egret.Point();
        //触摸移动，设置小球的位置
        this.p1 = new egret.Point();
        this.p2 = new egret.Point();
        //触摸结束，隐藏虚拟摇杆
        /**P4是专门用来检测左侧摇杆的点 */
        this.p4 = new egret.Point();
    }
    RockerLogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new RockerLogic();
        }
        return this.instance;
    };
    RockerLogic.prototype.openUI = function (con, _ui, arg) {
        if (arg === void 0) { arg = null; }
        if (this.ui == null) {
            this.ui = _ui;
            con.addChild(this.ui);
            if (this.ui.inited) {
                this.init();
            }
            this.ui.logic = this;
        }
        /**显示或隐藏摇杆 */
        //this.ui.visible = false;
    };
    RockerLogic.prototype.init = function () {
        //console.log("RockerLogic.init", this.ui.inited, this.ui.logic);
        /**中间球半径 */
        this.ballRadius = this.ui.ball.height / 2;
        /**外面球半径 */
        this.circleRadius = this.ui.circle.height / 2;
        //获取中心点
        this.centerX = this.circleRadius;
        this.centerY = this.circleRadius;
        //设置锚点
        this.ui.anchorOffsetX = this.circleRadius;
        this.ui.anchorOffsetY = this.circleRadius;
        this.ui.ball.anchorOffsetX = this.ballRadius;
        this.ui.ball.anchorOffsetY = this.ballRadius;
        //设置小球初始位置
        this.ui.ball.x = this.centerX;
        console.log(this.ui.ball.x);
        this.ui.ball.y = this.centerY;
        console.log(this.ui.ball.y);
        //this.initCrood();
        //this.stopbtn();
    };
    /**启动虚拟摇杆 (监听事件根据实际情况设置，不然点一下UI上的其他按钮，也会触发虚拟摇杆事件。)*/
    RockerLogic.prototype.start = function () {
        this.started = true;
        if (!GameData.GameStage.hasEventListener(egret.TouchEvent.TOUCH_BEGIN)) {
            GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
        }
        //if (!GameData.GameStage.hasEventListener(egret.TouchEvent.TOUCH_END)) {
        GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
        //}
        if (!GameData.GameStage.hasEventListener(egret.TouchEvent.TOUCH_MOVE)) {
            GameData.GameStage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
        }
    };
    /**停止虚拟摇杆*/
    RockerLogic.prototype.stop = function () {
        this.started = false;
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
        GameData.GameStage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
        this.touchID = null;
    };
    /**在哪触摸开始，就在哪显示虚拟摇杆*/
    RockerLogic.prototype.onTouchBegin = function (e) {
        var _this = this;
        if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
            return;
        }
        //this.player = Player.getInstance();
        //点击摇杆时 屏蔽所有碰撞
        GameData.GameStage.$hitTest = function (x, y) { return _this.ui; };
        this.ui.circle.$hitTest = function (x, y) { return _this.ui; };
        this.touchID = e.touchPointID;
        this.p3.x = e.stageX;
        this.p3.y = e.stageY;
        if (this.p3.x < 500) {
            this.ui.visible = true;
            this.ui.x = this.p3.x;
            this.ui.y = this.p3.y;
            this.p1.x = this.ui.x;
            this.p1.y = this.ui.y;
            this.ui.ball.x = this.centerX;
            this.ui.ball.y = this.centerY;
        }
        if (this.p3.x > 950 && this.p3.x < 1100 && this.p3.y > 430 && this.p3.y < 580) {
            this.isatk = false;
            //this.player.state==PLAYERSTATE.ATK;
            //Maplogic.getInstance().role.state == PLAYERSTATE.ATK;
        }
        else {
            this.isatk = true;
        }
    };
    RockerLogic.prototype.btn1 = function () {
        if (this.isatk == false) {
            this.isatk = true;
        }
        else {
            return;
        }
    };
    RockerLogic.prototype.onTouchMove = function (e) {
        if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
            return;
        }
        this.p2.x = e.stageX;
        this.p2.y = e.stageY;
        //计算两点距离
        var dist = egret.Point.distance(this.p1, this.p2);
        var angle = Math.atan2(e.stageY - this.ui.y, e.stageX - this.ui.x);
        //console.log(angle+"滑动方向")
        //手指距离在圆环范围内		
        if (this.p2.x < 500) {
            if (dist <= (this.circleRadius - this.ballRadius)) {
                this.ui.ball.x = this.centerX + e.stageX - this.ui.x;
                this.ui.ball.y = this.centerY + e.stageY - this.ui.y;
                //手指距离在圆环范围外
            }
            else {
                this.ui.ball.x = Math.cos(angle) * (this.circleRadius - this.ballRadius) + this.centerX;
                this.ui.ball.y = Math.sin(angle) * (this.circleRadius - this.ballRadius) + this.centerY;
            }
            if (dist >= 3) {
                var p1 = new egret.Point(this.ui.ball.x, this.ui.ball.y);
                var p2 = new egret.Point(this.centerX, this.centerY);
                var dis = egret.Point.distance(p1, p2);
                var rate = dis / (this.circleRadius - this.ballRadius);
                this.moveBall(angle, rate);
            }
            this.changetime = egret.getTimer();
            e.stopImmediatePropagation();
        }
    };
    RockerLogic.prototype.onTouchEnd = function (e) {
        this.p4.x = e.stageX;
        //触摸结束时隐藏摇杆
        if (this.p4.x < 500) {
            this.ui.visible = false;
        }
        GameLogic.getInstance().openHit();
        this.touchID = null;
        if (Maplogic.getInstance().role != null && Maplogic.getInstance().role.state == PLAYERSTATE.DEAD) {
            return;
        }
        this.p2.x = e.stageX;
        this.p2.y = e.stageY;
        if (this.controlplayer != null) {
            this.controlplayer.updateDirection(null);
        }
        //this.initCrood();
        //小球恢复初始位置
        // this.ui.ball.x = this.centerX;
        // this.ui.ball.y = this.centerY;
        if (this.p3.x > 950 && this.p3.x < 1100 && this.p3.y > 430 && this.p3.y < 580) {
            this.isatk = true;
        }
    };
    /**要控制的球 */
    RockerLogic.prototype.setControlPlayer = function (ball) {
        this.controlplayer = ball;
    };
    /**球体移动 */
    RockerLogic.prototype.moveBall = function (hu, rate) {
        if (this.controlplayer != null) {
            var dir = hu * 180 / Math.PI + 90;
            this.controlplayer.updateDirection(dir);
        }
    };
    RockerLogic.prototype.clear = function () {
        this.controlplayer = null;
        this.stop();
        if (this.ui != null && this.ui.parent != null) {
            this.ui.parent.removeChild(this.ui);
        }
        this.ui = null;
    };
    return RockerLogic;
}());
__reflect(RockerLogic.prototype, "RockerLogic");
var SkinLogic = (function () {
    function SkinLogic() {
    }
    SkinLogic.getInstance = function () {
        if (this.instance == null) {
            this.instance = new SkinLogic();
        }
        return this.instance;
    };
    SkinLogic.prototype.initSkinData = function () {
        this.skins = {};
        var data = RES.getRes("data_json");
        for (var key in data) {
            var o = data[key];
            var vo = new SkinVO();
            vo.id = parseInt(o.id);
            vo.type = parseInt(o.type);
            vo.max = parseInt(o.max);
            vo.state = SKINSTATE.UNLOCK;
            this.skins[vo.id] = vo;
        }
    };
    SkinLogic.prototype.getSkinVOByID = function (id) {
        return this.skins[id];
    };
    return SkinLogic;
}());
__reflect(SkinLogic.prototype, "SkinLogic");
var BeginUI = (function (_super) {
    __extends(BeginUI, _super);
    function BeginUI() {
        return _super.call(this, "BeginSkin") || this;
        //super("BeginSkinHeng");
    }
    return BeginUI;
}(BaseUI));
__reflect(BeginUI.prototype, "BeginUI");
var GameUI = (function (_super) {
    __extends(GameUI, _super);
    function GameUI() {
        var _this = _super.call(this, "RockerSkin") || this;
        _this = _super.call(this, "GameSkin") || this;
        return _this;
    }
    return GameUI;
}(BaseUI));
__reflect(GameUI.prototype, "GameUI");
var MapCon = (function (_super) {
    __extends(MapCon, _super);
    function MapCon() {
        return _super.call(this) || this;
    }
    MapCon.prototype.clear = function () {
        if (this.logic != null) {
            this.logic.clear();
        }
        this.logic = null;
    };
    return MapCon;
}(egret.DisplayObjectContainer));
__reflect(MapCon.prototype, "MapCon");
var Rocker = (function (_super) {
    __extends(Rocker, _super);
    function Rocker() {
        var _this = _super.call(this, "RockerSkin") || this;
        _this.once(egret.Event.ADDED_TO_STAGE, _this.rockerInit, _this);
        return _this;
    }
    //	private Rocker:roleControl;
    Rocker.prototype.rockerInit = function () {
        //、this.Rocker=new roleControl(this.ballatk,this.circleatk,this.ballatk.height/2,this.circleatk.height/2);
        //、this.Rocker.yaoganInit(this.stage);
    };
    return Rocker;
}(BaseUI));
__reflect(Rocker.prototype, "Rocker");
var AIPlayer = (function (_super) {
    __extends(AIPlayer, _super);
    function AIPlayer(vo) {
        return _super.call(this, vo) || this;
    }
    /** 每一帧执行 */
    AIPlayer.prototype.update = function () {
        _super.prototype.update.call(this);
        this.checkState();
    };
    /**游荡机制 */
    AIPlayer.prototype.checkState = function () {
        //边界-->转向
        if (this.checkBound()) {
            return;
        }
        //3秒-->转向
        this.checkTime();
    };
    /**边界判断 */
    AIPlayer.prototype.checkBound = function () {
        var bool = false;
        var a = 0;
        var b = 360;
        var dis = this.vo.radius - this.vo.circleRadius;
        if (this.x < dis) {
            this.x = dis;
            bool = true;
            b = 180;
        }
        else if (this.x > DesignConst.mapwidth - dis) {
            this.x = DesignConst.mapwidth - dis;
            bool = true;
            a = 180;
            b = 360;
        }
        if (this.y < dis) {
            this.y = dis;
            bool = true;
            if (b == 180) {
                a = 90;
                b = 180;
            }
            else if (a == 180) {
                a = 180;
                b = 270;
            }
            else {
                a = 90;
                b = 270;
            }
        }
        else if (this.y > DesignConst.mapheight - dis) {
            this.y = DesignConst.mapheight - dis;
            bool = true;
            if (b == 180) {
                a = 0;
                b = 90;
            }
            else if (a < 0) {
                a = -90;
                b = 0;
            }
            else {
                a = -90;
                b = 90;
            }
        }
        if (bool) {
            this.changeDirection(a, b);
        }
        return bool;
    };
    /**判断时间 每3秒变一次 */
    AIPlayer.prototype.checkTime = function () {
        var newtime = egret.getTimer();
        var changetime = 3000;
        if (newtime - this.lasttime >= 3000) {
            this.lasttime = newtime;
            this.changeDirection();
        }
    };
    /**每帧更新坐标 */
    AIPlayer.prototype.updateCrood = function () {
        var hu = this.vo.direction * Math.PI / 180;
        this.x += this.vo.move_speed * Math.sin(hu);
        this.y -= this.vo.move_speed * Math.cos(hu);
    };
    AIPlayer.prototype.wait = function () {
        this.x = Math.random() * DesignConst.mapwidth;
        this.y = Math.random() * DesignConst.mapheight;
    };
    AIPlayer.prototype.move = function () {
        this.changeDirection();
    };
    AIPlayer.prototype.defence = function () {
        this.updateKnifes();
    };
    AIPlayer.prototype.clear = function () {
    };
    AIPlayer.prototype.reset = function () {
    };
    AIPlayer.prototype.destroy = function () {
    };
    return AIPlayer;
}(Player));
__reflect(AIPlayer.prototype, "AIPlayer");
window['AIPlayer'] = AIPlayer;
var BeginPlayer = (function (_super) {
    __extends(BeginPlayer, _super);
    function BeginPlayer(vo) {
        var _this = _super.call(this, vo) || this;
        _this.touchEnabled = true;
        _this.touchChildren = false;
        return _this;
    }
    /** 每一帧执行 */
    BeginPlayer.prototype.update = function () {
        this.con.rotation += this.vo.turn_speed;
    };
    BeginPlayer.prototype.initView = function () {
        _super.prototype.initView.call(this);
        this.state = PLAYERSTATE.DEFENCE;
        this.lbl_name.text = "+2";
        this.icon = new egret.Bitmap();
        this.addChild(this.icon);
    };
    BeginPlayer.prototype.updateKnifes = function () {
        if (this.knifes == null || this.knifes.length == 0) {
            _super.prototype.updateKnifes.call(this);
            return;
        }
        var n = this.vo.knife_num;
        if (n >= DesignConst.player_knife_max) {
            n = DesignConst.player_knife_max;
        }
        for (var i = 0; i < this.knifes.length; i++) {
            var knife = this.knifes[i];
            knife.texture = RES.getRes("dao_" + this.vo.skinvo.id);
            knife.scaleX = knife.scaleY = 1;
            knife.anchorOffsetX = knife.width / 2;
            knife.anchorOffsetY = -this.vo.radius;
            //knife.rotation = 180* i / n;
            knife.rotation = 180;
        }
    };
    BeginPlayer.prototype.updateCenter = function (s) {
        this.beginstate = s;
        switch (s) {
            case BEGINSTATE.NORMAL:
                this.lbl_name.text = "玩家";
                this.lbl_name.width = this.bg_diameter;
                this.lbl_name.anchorOffsetX = this.lbl_name.width / 2;
                this.lbl_name.anchorOffsetY = this.lbl_name.height / 2;
                this.lbl_name.y = 0;
                this.lbl_name.visible = true;
                this.icon.visible = false;
                break;
            case BEGINSTATE.WATCHADD:
                this.icon.texture = RES.getRes("game_json.video");
                this.icon.anchorOffsetX = this.icon.width / 2;
                this.icon.anchorOffsetY = this.icon.height / 2;
                this.icon.y = -10;
                this.icon.visible = true;
                this.lbl_name.text = "+3";
                this.lbl_name.anchorOffsetX = this.lbl_name.width / 2;
                this.lbl_name.anchorOffsetY = this.lbl_name.height / 2;
                this.lbl_name.y = this.icon.height / 2 + 2;
                break;
            case BEGINSTATE.SHAREADD:
                this.icon.texture = RES.getRes("game_json.share");
                this.icon.anchorOffsetX = this.icon.width / 2;
                this.icon.anchorOffsetY = this.icon.height / 2;
                this.icon.y = -10;
                this.icon.visible = true;
                this.lbl_name.text = "+2";
                this.lbl_name.anchorOffsetX = this.lbl_name.width / 2;
                this.lbl_name.anchorOffsetY = this.lbl_name.height / 2;
                this.lbl_name.y = this.icon.height / 2 + 2;
                break;
        }
    };
    BeginPlayer.prototype.updateLblName = function () {
    };
    BeginPlayer.prototype.clear = function () {
    };
    BeginPlayer.prototype.reset = function () {
    };
    BeginPlayer.prototype.destroy = function () {
    };
    return BeginPlayer;
}(Player));
__reflect(BeginPlayer.prototype, "BeginPlayer");
var KnifePlayer = (function (_super) {
    __extends(KnifePlayer, _super);
    function KnifePlayer() {
        return _super.call(this) || this;
    }
    KnifePlayer.prototype.init = function (id, b) {
        if (b === void 0) { b = true; }
        this.id = id;
        if (this.bg == null) {
            this.bg = ObjectPool.getObject("BaseBitmap");
        }
        this.bg.texture = RES.getRes("dao_2");
        this.bg.scaleX = this.bg.scaleY = DesignConst.knifescale;
        if (this.aa == 1) {
            this.bg.rotation = Math.random() * 360;
        }
        this.bg.anchorOffsetX = this.bg.width / 2;
        this.bg.anchorOffsetY = this.bg.height / 2;
        this.addChild(this.bg);
        if (b) {
            this.state = KNIFESTATE.NORMAL;
            this.birth();
        }
        else {
            this.state = KNIFESTATE.FLYING;
        }
    };
    Object.defineProperty(KnifePlayer.prototype, "state", {
        get: function () {
            return this._state;
        },
        set: function (v) {
            this._state = v;
        },
        enumerable: true,
        configurable: true
    });
    KnifePlayer.prototype.birth = function () {
        this.x = Math.random() * DesignConst.mapwidth;
        this.y = Math.random() * DesignConst.mapheight;
    };
    KnifePlayer.prototype.clear = function () {
        this._state = KNIFESTATE.NORMAL;
    };
    KnifePlayer.prototype.reset = function () {
        this._state = KNIFESTATE.NORMAL;
    };
    KnifePlayer.prototype.destroy = function () {
    };
    return KnifePlayer;
}(egret.DisplayObjectContainer));
__reflect(KnifePlayer.prototype, "KnifePlayer", ["IPool"]);
window['KnifePlayer'] = KnifePlayer;
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Main.prototype.createChildren = function () {
        _super.prototype.createChildren.call(this);
        console.log("initMain:屏幕宽高", this.stage.stageWidth, this.stage.stageHeight);
        RES.setMaxLoadingThread(1);
        GameData.GameStage = this.stage;
        GameData.stageWidth = this.stage.stageWidth;
        GameData.stageHeight = this.stage.stageHeight;
        GameData.main = this;
        egret.lifecycle.addLifecycleListener(function (context) {
            // custom lifecycle plugin
        });
        egret.lifecycle.onPause = function () {
            egret.ticker.pause();
        };
        egret.lifecycle.onResume = function () {
            egret.ticker.resume();
        };
        //inject the custom material parser
        //注入自定义的素材解析器
        var assetAdapter = new AssetAdapter();
        egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
        this.runGame().catch(function (e) {
            console.log(e);
        });
    };
    Main.prototype.runGame = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.loadResource()];
                    case 1:
                        _a.sent();
                        this.createGameScene();
                        return [2 /*return*/];
                }
            });
        });
    };
    Main.prototype.loadResource = function () {
        return __awaiter(this, void 0, void 0, function () {
            var loadingView, e_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 4, , 5]);
                        loadingView = new LoadingUI();
                        this.stage.addChild(loadingView);
                        return [4 /*yield*/, RES.loadConfig("resource/default.res.json", "resource/")];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.loadTheme()];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, RES.loadGroup("preload", 0, loadingView)];
                    case 3:
                        _a.sent();
                        SkinLogic.getInstance().initSkinData();
                        this.stage.removeChild(loadingView);
                        return [3 /*break*/, 5];
                    case 4:
                        e_1 = _a.sent();
                        console.error(e_1);
                        return [3 /*break*/, 5];
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    Main.prototype.loadTheme = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            // load skin theme configuration file, you can manually modify the file. And replace the default skin.
            //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
            var theme = new eui.Theme("resource/default.thm.json", _this.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, function () {
                resolve();
            }, _this);
        });
    };
    /**
     * 创建场景界面
     * Create scene interface
     */
    Main.prototype.createGameScene = function () {
        GameConst.rewardAdId = GameConst.s1 + UIConst.s1 + HttpEvent.s1;
        GameConst.bannerAdId = GameConst.s1 + UIConst.s2 + HttpEvent.s2;
        BeginLogic.getInstance().openUI(this, new BeginUI());
        WxApi.getInstance().init();
    };
    return Main;
}(eui.UILayer));
__reflect(Main.prototype, "Main");
var RolePlayer = (function (_super) {
    __extends(RolePlayer, _super);
    function RolePlayer(vo) {
        var _this = _super.call(this, vo) || this;
        RolePlayer.instanceRole = _this;
        return _this;
    }
    RolePlayer.getInstance = function () {
        return this.instanceRole;
    };
    RolePlayer.prototype.setState = function (v) {
        var up = false;
        if (this.state == PLAYERSTATE.DEFENCE && v == PLAYERSTATE.MOVE) {
            up = true;
        }
        _super.prototype.setState.call(this, v);
        // if(up){
        // 	this.updateKnifes();
        // }
    };
    RolePlayer.prototype.wait = function () {
        _super.prototype.wait.call(this);
    };
    RolePlayer.prototype.move = function () {
    };
    RolePlayer.prototype.defence = function () {
        _super.prototype.defence.call(this);
    };
    /** 每一帧执行 */
    RolePlayer.prototype.update = function () {
        _super.prototype.update.call(this);
        this.checkBound();
        Maplogic.getInstance().updateMapCrood();
    };
    /**边界判断 */
    RolePlayer.prototype.checkBound = function () {
        var dis = this.vo.radius - this.vo.circleRadius;
        if (this.x < dis) {
            this.x = dis;
        }
        else if (this.x > DesignConst.mapwidth - dis) {
            this.x = DesignConst.mapwidth - dis;
        }
        if (this.y < dis) {
            this.y = dis;
        }
        else if (this.y > DesignConst.mapheight - dis) {
            this.y = DesignConst.mapheight - dis;
        }
        return false;
    };
    /**获取左摇杆方向 */
    RolePlayer.prototype.updateDirection = function (dir) {
        this.vo.direction = dir;
        if (dir != null) {
            //	this.state = PLAYERSTATE.ATK;
        }
        else {
            //this.state = PLAYERSTATE.CRUISE;
        }
    };
    /**获取防御摇杆方向 */
    RolePlayer.prototype.updateRightDirection = function (RightDir) {
        this.vo.Rightdirection = RightDir;
        if (RightDir != null) {
            this.state = PLAYERSTATE.DEFENCE;
            this.stat = true;
        }
        else {
            this.state = PLAYERSTATE.CRUISE;
        }
    };
    /**获取攻击状态 */
    RolePlayer.prototype.updateATKDirection = function (isAtk) {
        if (isAtk != null && isAtk == false) {
            this.state = PLAYERSTATE.ATK;
        }
        if (this.stat == false) {
            this.state = PLAYERSTATE.CRUISE;
        }
    };
    RolePlayer.prototype.clear = function () {
    };
    RolePlayer.prototype.reset = function () {
    };
    RolePlayer.prototype.destroy = function () {
    };
    return RolePlayer;
}(Player));
__reflect(RolePlayer.prototype, "RolePlayer");
var PlayerVO = (function () {
    function PlayerVO() {
        /**刀*/
        this.knife_num = 0;
        /** 离圆心的距离 */
        this.dis_from_circle = 64;
        /**方向*/
        this.direction = 0;
        /**右摇杆的方向 */
        this.Rightdirection = 0;
    }
    PlayerVO.prototype.clear = function () {
        this.skinvo = null;
    };
    PlayerVO.prototype.reset = function () {
        this.skinvo = null;
    };
    PlayerVO.prototype.destroy = function () {
    };
    return PlayerVO;
}());
__reflect(PlayerVO.prototype, "PlayerVO", ["IPool"]);
window['PlayerVO'] = PlayerVO;
var SkinVO = (function () {
    function SkinVO() {
    }
    return SkinVO;
}());
__reflect(SkinVO.prototype, "SkinVO");

;window.Main = Main;